diff options
author | nicm <nicm> | 2016-10-16 17:55:14 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-10-16 17:55:14 +0000 |
commit | ddc4512d2e0eda6c705e002cb5dbf80719d709e1 (patch) | |
tree | cd9ff99f4b1ccb3e76ab99633d59772ae07c3092 /cmd-run-shell.c | |
parent | bfe14b531267f3762a518f98b72a3148a134396a (diff) |
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 'cmd-run-shell.c')
-rw-r--r-- | cmd-run-shell.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/cmd-run-shell.c b/cmd-run-shell.c index c81c76f8..ad2d4c2f 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -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); |