aboutsummaryrefslogtreecommitdiff
path: root/cmd-if-shell.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2015-04-22 10:05:54 +0100
committerThomas Adam <thomas@xteddy.org>2015-04-22 10:05:54 +0100
commit0a88377086329786c438d4973365fdb21186f4e4 (patch)
treedf5b091b400df84974f58bbfbb78ee26ccb9a5f6 /cmd-if-shell.c
parentb25dc423b0b1369aaec5dee8e051d541bd55043f (diff)
parent3909aff06aa6de748ae057cab1e723eec2387edd (diff)
downloadrtmux-0a88377086329786c438d4973365fdb21186f4e4.tar.gz
rtmux-0a88377086329786c438d4973365fdb21186f4e4.tar.bz2
rtmux-0a88377086329786c438d4973365fdb21186f4e4.zip
Merge branch 'obsd-master'
Diffstat (limited to 'cmd-if-shell.c')
-rw-r--r--cmd-if-shell.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index 9659511e..cdd2135c 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -44,11 +44,14 @@ const struct cmd_entry cmd_if_shell_entry = {
};
struct cmd_if_shell_data {
- char *cmd_if;
- char *cmd_else;
- struct cmd_q *cmdq;
- int bflag;
- int started;
+ char *cmd_if;
+ char *cmd_else;
+
+ struct cmd_q *cmdq;
+ struct mouse_event mouse;
+
+ int bflag;
+ int references;
};
enum cmd_retval
@@ -95,23 +98,26 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
}
return (CMD_RETURN_ERROR);
}
- cmdq_run(cmdq, cmdlist, NULL);
+ cmdq_run(cmdq, cmdlist, &cmdq->item->mouse);
cmd_list_free(cmdlist);
return (CMD_RETURN_NORMAL);
}
cdata = xmalloc(sizeof *cdata);
+
cdata->cmd_if = xstrdup(args->argv[1]);
if (args->argc == 3)
cdata->cmd_else = xstrdup(args->argv[2]);
else
cdata->cmd_else = NULL;
+
cdata->bflag = args_has(args, 'b');
- cdata->started = 0;
cdata->cmdq = cmdq;
+ memcpy(&cdata->mouse, &cmdq->item->mouse, sizeof cdata->mouse);
cmdq->references++;
+ cdata->references = 1;
job_run(shellcmd, s, cmd_if_shell_callback, cmd_if_shell_free, cdata);
free(shellcmd);
@@ -146,13 +152,12 @@ cmd_if_shell_callback(struct job *job)
return;
}
- cdata->started = 1;
-
cmdq1 = cmdq_new(cmdq->client);
cmdq1->emptyfn = cmd_if_shell_done;
cmdq1->data = cdata;
- cmdq_run(cmdq1, cmdlist, NULL);
+ cdata->references++;
+ cmdq_run(cmdq1, cmdlist, &cdata->mouse);
cmd_list_free(cmdlist);
}
@@ -164,12 +169,14 @@ cmd_if_shell_done(struct cmd_q *cmdq1)
if (cmdq1->client_exit >= 0)
cmdq->client_exit = cmdq1->client_exit;
+ cmdq_free(cmdq1);
+
+ if (--cdata->references != 0)
+ return;
if (!cmdq_free(cmdq) && !cdata->bflag)
cmdq_continue(cmdq);
- cmdq_free(cmdq1);
-
free(cdata->cmd_else);
free(cdata->cmd_if);
free(cdata);
@@ -181,7 +188,7 @@ cmd_if_shell_free(void *data)
struct cmd_if_shell_data *cdata = data;
struct cmd_q *cmdq = cdata->cmdq;
- if (cdata->started)
+ if (--cdata->references != 0)
return;
if (!cmdq_free(cmdq) && !cdata->bflag)