summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-run-shell.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-03-22 15:49:55 +0000
committernicm <nicm@openbsd.org>2013-03-22 15:49:55 +0000
commitde9a15de72aa0757cd1a1bfd8aaeafe306453bdc (patch)
treeb3a7edbdb60e25f3fca5f750c86f1ef8165cf3b6 /usr.bin/tmux/cmd-run-shell.c
parentsync (diff)
downloadwireguard-openbsd-de9a15de72aa0757cd1a1bfd8aaeafe306453bdc.tar.xz
wireguard-openbsd-de9a15de72aa0757cd1a1bfd8aaeafe306453bdc.zip
Add functions to allocate and free command contexts rather than doing it
all on the stack.
Diffstat (limited to 'usr.bin/tmux/cmd-run-shell.c')
-rw-r--r--usr.bin/tmux/cmd-run-shell.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c
index 9d15e5359bd..d341258bffe 100644
--- a/usr.bin/tmux/cmd-run-shell.c
+++ b/usr.bin/tmux/cmd-run-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-run-shell.c,v 1.14 2012/11/27 15:09:35 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.15 2013/03/22 15:49:55 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -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);