From a19cac5c46189c7c6eb4a6f4ccc7336d54676dba Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 15 Sep 2021 07:38:30 +0000 Subject: For the moment, restore if-shell and run-shell to parsing at the last moment (when the shell command completes) rather than when first invoked, GitHub issue 2872. --- cmd-run-shell.c | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'cmd-run-shell.c') diff --git a/cmd-run-shell.c b/cmd-run-shell.c index 7d672f85..537a5e5f 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -54,15 +54,15 @@ const struct cmd_entry cmd_run_shell_entry = { }; struct cmd_run_shell_data { - struct client *client; - char *cmd; - struct cmd_list *cmdlist; - char *cwd; - struct cmdq_item *item; - struct session *s; - int wp_id; - struct event timer; - int flags; + struct client *client; + char *cmd; + struct args_command_state *state; + char *cwd; + struct cmdq_item *item; + struct session *s; + int wp_id; + struct event timer; + int flags; }; static enum args_parse_type @@ -132,9 +132,8 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) if (cmd != NULL) cdata->cmd = format_single_from_target(item, cmd); } else { - cdata->cmdlist = args_make_commands_now(self, item, 0, 1); - if (cdata->cmdlist == NULL) - return (CMD_RETURN_ERROR); + cdata->state = args_make_commands_prepare(self, item, 0, NULL, + wait, 1); } if (args_has(args, 't') && wp != NULL) @@ -179,8 +178,10 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg) struct client *c = cdata->client; const char *cmd = cdata->cmd; struct cmdq_item *item = cdata->item, *new_item; + struct cmd_list *cmdlist; + char *error; - if (cdata->cmdlist == NULL && cmd != NULL) { + if (cdata->state == NULL && cmd != NULL) { if (job_run(cmd, 0, NULL, cdata->s, cdata->cwd, NULL, cmd_run_shell_callback, cmd_run_shell_free, cdata, cdata->flags, -1, -1) == NULL) @@ -188,15 +189,20 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg) return; } - if (cdata->cmdlist != NULL) { - if (item == NULL) { - new_item = cmdq_get_command(cdata->cmdlist, NULL); - cmdq_append(c, new_item); - } else { - new_item = cmdq_get_command(cdata->cmdlist, - cmdq_get_state(item)); - cmdq_insert_after(item, new_item); - } + cmdlist = args_make_commands(cdata->state, 0, NULL, &error); + if (cmdlist == NULL) { + if (cdata->item == NULL) { + *error = toupper((u_char)*error); + status_message_set(c, -1, 1, 0, "%s", error); + } else + cmdq_error(cdata->item, "%s", error); + free(error); + } else if (item == NULL) { + new_item = cmdq_get_command(cmdlist, NULL); + cmdq_append(c, new_item); + } else { + new_item = cmdq_get_command(cmdlist, cmdq_get_state(item)); + cmdq_insert_after(item, new_item); } if (cdata->item != NULL) @@ -264,8 +270,8 @@ cmd_run_shell_free(void *data) session_remove_ref(cdata->s, __func__); if (cdata->client != NULL) server_client_unref(cdata->client); - if (cdata->cmdlist != NULL) - cmd_list_free(cdata->cmdlist); + if (cdata->state != NULL) + args_make_commands_free(cdata->state); free(cdata->cwd); free(cdata->cmd); free(cdata); -- cgit v1.2.3