diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2013-03-22 15:49:55 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2013-03-22 15:49:55 +0000 |
commit | d1e6ce26722e3a0774d240e39bbc69b07e93c48b (patch) | |
tree | 4ac0c275feab5c23da70c25dbc62a605208a45e5 /cmd-if-shell.c | |
parent | 29613f2f31117ed898455fdf75dd7b69d18129f3 (diff) | |
download | rtmux-d1e6ce26722e3a0774d240e39bbc69b07e93c48b.tar.gz rtmux-d1e6ce26722e3a0774d240e39bbc69b07e93c48b.tar.bz2 rtmux-d1e6ce26722e3a0774d240e39bbc69b07e93c48b.zip |
Add functions to allocate and free command contexts rather than doing it
all on the stack.
Diffstat (limited to 'cmd-if-shell.c')
-rw-r--r-- | cmd-if-shell.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 4cb9de82..ab69e8b5 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -47,7 +47,7 @@ const struct cmd_entry cmd_if_shell_entry = { struct cmd_if_shell_data { char *cmd_if; char *cmd_else; - struct cmd_ctx ctx; + struct cmd_ctx *ctx; }; enum cmd_retval @@ -63,12 +63,9 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) cdata->cmd_else = xstrdup(args->argv[2]); else cdata->cmd_else = NULL; - 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_if_shell_callback, cmd_if_shell_free, cdata); @@ -79,7 +76,7 @@ void cmd_if_shell_callback(struct job *job) { struct cmd_if_shell_data *cdata = job->data; - struct cmd_ctx *ctx = &cdata->ctx; + struct cmd_ctx *ctx = cdata->ctx; struct cmd_list *cmdlist; char *cause, *cmd; @@ -105,14 +102,11 @@ void cmd_if_shell_free(void *data) { struct cmd_if_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_else); free(cdata->cmd_if); |