diff options
author | 2016-04-29 14:05:24 +0000 | |
---|---|---|
committer | 2016-04-29 14:05:24 +0000 | |
commit | 39ed82a7040e93ce32e5a1cd9557175c611d0e2c (patch) | |
tree | e09b293158662d4ae44f1dea96f38452b0080e63 /usr.bin/tmux/cmd-queue.c | |
parent | Panic when attempting to execute a scsi command with no discipline (diff) | |
download | wireguard-openbsd-39ed82a7040e93ce32e5a1cd9557175c611d0e2c.tar.xz wireguard-openbsd-39ed82a7040e93ce32e5a1cd9557175c611d0e2c.zip |
Final parts of command hooks, add before- and after- hooks to each command.
Diffstat (limited to 'usr.bin/tmux/cmd-queue.c')
-rw-r--r-- | usr.bin/tmux/cmd-queue.c | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c index daf71ea8844..691ac376f1e 100644 --- a/usr.bin/tmux/cmd-queue.c +++ b/usr.bin/tmux/cmd-queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-queue.c,v 1.35 2016/01/19 16:01:30 nicm Exp $ */ +/* $OpenBSD: cmd-queue.c,v 1.36 2016/04/29 14:05:24 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -186,6 +186,9 @@ static enum cmd_retval cmdq_continue_one(struct cmd_q *cmdq) { struct cmd *cmd = cmdq->cmd; + const char *name = cmd->entry->name; + struct session *s; + struct hooks *hooks; enum cmd_retval retval; char *tmp; int flags = !!(cmd->flags & CMD_CONTROL); @@ -197,19 +200,51 @@ cmdq_continue_one(struct cmd_q *cmdq) cmdq->time = time(NULL); cmdq->number++; - cmdq_guard(cmdq, "begin", flags); + if (~cmdq->flags & CMD_Q_REENTRY) + cmdq_guard(cmdq, "begin", flags); - if (cmd_prepare_state(cmd, cmdq, NULL) != 0) + if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0) goto error; + + if (~cmdq->flags & CMD_Q_NOHOOKS) { + s = NULL; + if (cmdq->state.tflag.s != NULL) + s = cmdq->state.tflag.s; + else if (cmdq->state.sflag.s != NULL) + s = cmdq->state.sflag.s; + else if (cmdq->state.c != NULL) + s = cmdq->state.c->session; + if (s != NULL) + hooks = s->hooks; + else + hooks = global_hooks; + + if (~cmdq->flags & CMD_Q_REENTRY) { + cmdq->flags |= CMD_Q_REENTRY; + if (hooks_wait(hooks, cmdq, NULL, + "before-%s", name) == 0) + return (CMD_RETURN_WAIT); + if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0) + goto error; + } + } else + hooks = NULL; + cmdq->flags &= ~CMD_Q_REENTRY; + retval = cmd->entry->exec(cmd, cmdq); if (retval == CMD_RETURN_ERROR) goto error; + if (hooks != NULL && hooks_wait(hooks, cmdq, NULL, + "after-%s", name) == 0) + retval = CMD_RETURN_WAIT; cmdq_guard(cmdq, "end", flags); + return (retval); error: cmdq_guard(cmdq, "error", flags); + cmdq->flags &= ~CMD_Q_REENTRY; return (CMD_RETURN_ERROR); } @@ -232,11 +267,18 @@ cmdq_continue(struct cmd_q *cmdq) if (empty) goto empty; - if (cmdq->item == NULL) { - cmdq->item = TAILQ_FIRST(&cmdq->queue); - cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list); - } else - cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry); + /* + * If the command isn't in the middle of running hooks (due to + * CMD_RETURN_WAIT), move onto the next command; otherwise, leave the + * state of the queue as it is. + */ + if (~cmdq->flags & CMD_Q_REENTRY) { + if (cmdq->item == NULL) { + cmdq->item = TAILQ_FIRST(&cmdq->queue); + cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list); + } else + cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry); + } do { while (cmdq->cmd != NULL) { |