summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-run-shell.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2016-10-16 17:55:14 +0000
committernicm <nicm@openbsd.org>2016-10-16 17:55:14 +0000
commit765b9a582c208af75c7304abae7e7e4c757934cb (patch)
treec6ba4d8161097c3d648fe4a1d213628591795591 /usr.bin/tmux/cmd-run-shell.c
parentUse the err(3) family of functions more consistently. (diff)
downloadwireguard-openbsd-765b9a582c208af75c7304abae7e7e4c757934cb.tar.xz
wireguard-openbsd-765b9a582c208af75c7304abae7e7e4c757934cb.zip
Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues being dispatched on demand from wherever the command happens to be added, they are now all dispatched from the top level server loop. Command queues may now also include callbacks as well as commands, and items may be inserted after the current command as well as at the end. This all makes command queues significantly more predictable and easier to use, and avoids the complex multiple nested command queues used by source-file, if-shell and friends. A mass rename of struct cmdq to a better name (cmdq_item probably) is coming.
Diffstat (limited to 'usr.bin/tmux/cmd-run-shell.c')
-rw-r--r--usr.bin/tmux/cmd-run-shell.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c
index e1f4795b506..2afe8e13589 100644
--- a/usr.bin/tmux/cmd-run-shell.c
+++ b/usr.bin/tmux/cmd-run-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-run-shell.c,v 1.39 2016/10/15 23:06:39 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.40 2016/10/16 17:55:14 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -51,7 +51,6 @@ const struct cmd_entry cmd_run_shell_entry = {
struct cmd_run_shell_data {
char *cmd;
struct cmd_q *cmdq;
- int bflag;
int wp_id;
};
@@ -92,6 +91,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
cwd = s->cwd;
else
cwd = NULL;
+
ft = format_create(cmdq, 0);
format_defaults(ft, cmdq->state.c, s, wl, wp);
shellcmd = format_expand(ft, args->argv[0]);
@@ -99,20 +99,24 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
cdata = xcalloc(1, sizeof *cdata);
cdata->cmd = shellcmd;
- cdata->bflag = args_has(args, 'b');
if (args_has(args, 't') && wp != NULL)
cdata->wp_id = wp->id;
else
cdata->wp_id = -1;
- cdata->cmdq = cmdq;
- cmdq->references++;
+ if (args_has(args, 't') && wp != NULL)
+ cdata->wp_id = wp->id;
+ else
+ cdata->wp_id = -1;
+
+ if (!args_has(args, 'b'))
+ cdata->cmdq = cmdq;
job_run(shellcmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free,
cdata);
- if (cdata->bflag)
+ if (args_has(args, 'b'))
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_WAIT);
}
@@ -121,16 +125,11 @@ static void
cmd_run_shell_callback(struct job *job)
{
struct cmd_run_shell_data *cdata = job->data;
- struct cmd_q *cmdq = cdata->cmdq;
- char *cmd, *msg, *line;
+ char *cmd = cdata->cmd, *msg, *line;
size_t size;
int retcode;
u_int lines;
- if (cmdq->flags & CMD_Q_DEAD)
- return;
- cmd = cdata->cmd;
-
lines = 0;
do {
if ((line = evbuffer_readline(job->event->input)) != NULL) {
@@ -163,16 +162,15 @@ cmd_run_shell_callback(struct job *job)
if (msg != NULL)
cmd_run_shell_print(job, msg);
free(msg);
+
+ if (cdata->cmdq != NULL)
+ cdata->cmdq->flags &= ~CMD_Q_WAITING;
}
static void
cmd_run_shell_free(void *data)
{
struct cmd_run_shell_data *cdata = data;
- struct cmd_q *cmdq = cdata->cmdq;
-
- if (!cmdq_free(cmdq) && !cdata->bflag)
- cmdq_continue(cmdq);
free(cdata->cmd);
free(cdata);