summaryrefslogtreecommitdiffstats
path: root/cmd-run-shell.c
diff options
context:
space:
mode:
authornicm <nicm>2021-09-15 07:38:30 +0000
committernicm <nicm>2021-09-15 07:38:30 +0000
commita19cac5c46189c7c6eb4a6f4ccc7336d54676dba (patch)
tree7a9b893a1c73031992296a8c870ad80cead1d575 /cmd-run-shell.c
parente6b40cb339e06b9084a9139a75d62fb7a6005448 (diff)
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.
Diffstat (limited to 'cmd-run-shell.c')
-rw-r--r--cmd-run-shell.c54
1 files changed, 30 insertions, 24 deletions
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);