=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-run-shell.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- src/usr.bin/tmux/cmd-run-shell.c 2013/03/24 09:33:35 1.17 +++ src/usr.bin/tmux/cmd-run-shell.c 2013/03/24 09:54:10 1.18 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-run-shell.c,v 1.17 2013/03/24 09:33:35 nicm Exp $ */ +/* $OpenBSD: cmd-run-shell.c,v 1.18 2013/03/24 09:54:10 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha @@ -29,7 +29,7 @@ * Runs a command without a window. */ -enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_q *); void cmd_run_shell_callback(struct job *); void cmd_run_shell_free(void *); @@ -37,8 +37,8 @@ const struct cmd_entry cmd_run_shell_entry = { "run-shell", "run", - "t:", 1, 1, - CMD_TARGET_PANE_USAGE " command", + "bt:", 1, 1, + "[-b] " CMD_TARGET_PANE_USAGE " shell-command", 0, NULL, NULL, @@ -47,7 +47,8 @@ struct cmd_run_shell_data { char *cmd; - struct cmd_ctx *ctx; + struct cmd_q *cmdq; + int bflag; u_int wp_id; }; @@ -55,12 +56,11 @@ 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 window_pane *wp; wp = window_pane_find_by_id(cdata->wp_id); if (wp == NULL) { - ctx->print(ctx, "%s", msg); + cmdq_print(cdata->cmdq, "%s", msg); return; } @@ -71,7 +71,7 @@ } enum cmd_retval -cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx) +cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct cmd_run_shell_data *cdata; @@ -81,7 +81,7 @@ struct window_pane *wp; struct format_tree *ft; - wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp); + wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp); if (wl == NULL) return (CMD_RETURN_ERROR); @@ -94,35 +94,37 @@ cdata = xmalloc(sizeof *cdata); cdata->cmd = shellcmd; + cdata->bflag = args_has(args, 'b'); cdata->wp_id = wp->id; - cdata->ctx = ctx; - cmd_ref_ctx(ctx); + cdata->cmdq = cmdq; + cmdq->references++; job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata); - return (CMD_RETURN_YIELD); /* don't let client exit */ + if (cdata->bflag) + return (CMD_RETURN_NORMAL); + return (CMD_RETURN_WAIT); } void cmd_run_shell_callback(struct job *job) { struct cmd_run_shell_data *cdata = job->data; - struct cmd_ctx *ctx = cdata->ctx; + struct cmd_q *cmdq = cdata->cmdq; char *cmd, *msg, *line; size_t size; int retcode; u_int lines; - if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD) + if (cmdq->dead) return; - if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD) - return; + cmd = cdata->cmd; lines = 0; do { if ((line = evbuffer_readline(job->event->input)) != NULL) { - cmd_run_shell_print (job, line); + cmd_run_shell_print(job, line); free(line); lines++; } @@ -140,8 +142,6 @@ free(line); } - cmd = cdata->cmd; - msg = NULL; if (WIFEXITED(job->status)) { if ((retcode = WEXITSTATUS(job->status)) != 0) @@ -152,7 +152,7 @@ } if (msg != NULL) { if (lines == 0) - ctx->info(ctx, "%s", msg); + cmdq_info(cmdq, "%s", msg); else cmd_run_shell_print(job, msg); free(msg); @@ -163,11 +163,10 @@ cmd_run_shell_free(void *data) { struct cmd_run_shell_data *cdata = data; - struct cmd_ctx *ctx = cdata->ctx; + struct cmd_q *cmdq = cdata->cmdq; - if (ctx->cmdclient != NULL) - ctx->cmdclient->flags |= CLIENT_EXIT; - cmd_free_ctx(ctx); + if (!cmdq_free(cmdq) && !cdata->bflag) + cmdq_continue(cmdq); free(cdata->cmd); free(cdata);