summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-if-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-if-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-if-shell.c')
-rw-r--r--usr.bin/tmux/cmd-if-shell.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c
index 7094458d744..ecec3a10d52 100644
--- a/usr.bin/tmux/cmd-if-shell.c
+++ b/usr.bin/tmux/cmd-if-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-if-shell.c,v 1.17 2012/08/11 07:32:16 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.18 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_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);