-/* $OpenBSD: cmd-if-shell.c,v 1.30 2015/04/21 15:18:06 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.31 2015/04/21 21:31:02 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
struct mouse_event mouse;
int bflag;
- int started;
+ int references;
};
enum cmd_retval
cdata->bflag = args_has(args, 'b');
- cdata->started = 0;
cdata->cmdq = cmdq;
memcpy(&cdata->mouse, &cmdq->item->mouse, sizeof cdata->mouse);
cmdq->references++;
+ cdata->references = 1;
job_run(shellcmd, s, cmd_if_shell_callback, cmd_if_shell_free, cdata);
free(shellcmd);
return;
}
- cdata->started = 1;
-
cmdq1 = cmdq_new(cmdq->client);
cmdq1->emptyfn = cmd_if_shell_done;
cmdq1->data = cdata;
+ cdata->references++;
cmdq_run(cmdq1, cmdlist, &cdata->mouse);
cmd_list_free(cmdlist);
}
if (cmdq1->client_exit >= 0)
cmdq->client_exit = cmdq1->client_exit;
+ cmdq_free(cmdq1);
+
+ if (--cdata->references != 0)
+ return;
if (!cmdq_free(cmdq) && !cdata->bflag)
cmdq_continue(cmdq);
- cmdq_free(cmdq1);
-
free(cdata->cmd_else);
free(cdata->cmd_if);
free(cdata);
struct cmd_if_shell_data *cdata = data;
struct cmd_q *cmdq = cdata->cmdq;
- if (cdata->started)
+ if (--cdata->references != 0)
return;
if (!cmdq_free(cmdq) && !cdata->bflag)