diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-02-18 23:20:21 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-02-18 23:20:21 +0000 |
commit | 293e331d69def60110bdc49b6453af905e0509b3 (patch) | |
tree | 3dbb4230607dc6bb0a40d3a1e9b71d0f56774c7a /cmd-run-shell.c | |
parent | 2a91025581ddaa934ffa471f5b27a33d19e4ea2d (diff) | |
download | rtmux-293e331d69def60110bdc49b6453af905e0509b3.tar.gz rtmux-293e331d69def60110bdc49b6453af905e0509b3.tar.bz2 rtmux-293e331d69def60110bdc49b6453af905e0509b3.zip |
Add functions to allocate and free command contexts rather than doing it all on
the stack.
Diffstat (limited to 'cmd-run-shell.c')
-rw-r--r-- | cmd-run-shell.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/cmd-run-shell.c b/cmd-run-shell.c index 44e796df..03cbc292 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -47,7 +47,7 @@ const struct cmd_entry cmd_run_shell_entry = { struct cmd_run_shell_data { char *cmd; - struct cmd_ctx ctx; + struct cmd_ctx *ctx; u_int wp_id; }; @@ -55,7 +55,7 @@ void cmd_run_shell_print(struct job *job, const char *msg) { struct cmd_run_shell_data *cdata = job->data; - struct cmd_ctx *ctx = &cdata->ctx; + struct cmd_ctx *ctx = cdata->ctx; struct window_pane *wp; wp = window_pane_find_by_id(cdata->wp_id); @@ -84,12 +84,9 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx) cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[0]); cdata->wp_id = wp->id; - memcpy(&cdata->ctx, ctx, sizeof cdata->ctx); - if (ctx->cmdclient != NULL) - ctx->cmdclient->references++; - if (ctx->curclient != NULL) - ctx->curclient->references++; + cdata->ctx = ctx; + cmd_ref_ctx(ctx); job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata); @@ -100,7 +97,7 @@ void cmd_run_shell_callback(struct job *job) { struct cmd_run_shell_data *cdata = job->data; - struct cmd_ctx *ctx = &cdata->ctx; + struct cmd_ctx *ctx = cdata->ctx; char *cmd, *msg, *line; size_t size; int retcode; @@ -154,14 +151,11 @@ void cmd_run_shell_free(void *data) { struct cmd_run_shell_data *cdata = data; - struct cmd_ctx *ctx = &cdata->ctx; + struct cmd_ctx *ctx = cdata->ctx; - if (ctx->cmdclient != NULL) { - ctx->cmdclient->references--; + if (ctx->cmdclient != NULL) ctx->cmdclient->flags |= CLIENT_EXIT; - } - if (ctx->curclient != NULL) - ctx->curclient->references--; + cmd_free_ctx(ctx); free(cdata->cmd); free(cdata); |