summaryrefslogtreecommitdiffstats
path: root/cmd-run-shell.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2013-03-22 15:49:55 +0000
committerNicholas Marriott <nicm@openbsd.org>2013-03-22 15:49:55 +0000
commitd1e6ce26722e3a0774d240e39bbc69b07e93c48b (patch)
tree4ac0c275feab5c23da70c25dbc62a605208a45e5 /cmd-run-shell.c
parent29613f2f31117ed898455fdf75dd7b69d18129f3 (diff)
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.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/cmd-run-shell.c b/cmd-run-shell.c
index 0fe7620b..ea7d1dcb 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);