summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2016-10-13 22:48:51 +0000
committernicm <nicm@openbsd.org>2016-10-13 22:48:51 +0000
commit45436ca5b5dc258d1b897f6edf4bedc83760d1b3 (patch)
tree2f83085b780623e6aa3f0657756446696f060711 /usr.bin/tmux/cmd-queue.c
parentIn rare cases the number of dropped messages changes a bit more. (diff)
downloadwireguard-openbsd-45436ca5b5dc258d1b897f6edf4bedc83760d1b3.tar.xz
wireguard-openbsd-45436ca5b5dc258d1b897f6edf4bedc83760d1b3.zip
Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target hooks should be using. So simplify it: - drop before hooks entirely, they don't seem to be very useful; - commands with special requirements now fire their own after hook (for example, if they change session or window, or if they have -t and -s and need to choose which one the hook uses as current target); - commands with no special requirements can have the CMD_AFTERHOOK flag added and they will use the -t state. At the moment new-session, new-window, split-window fire their own hook, and display-message uses the flag. The remaining commands still need to be looked at.
Diffstat (limited to 'usr.bin/tmux/cmd-queue.c')
-rw-r--r--usr.bin/tmux/cmd-queue.c90
1 files changed, 27 insertions, 63 deletions
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index b976e984546..aefc1a3ddd5 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.39 2016/10/13 10:01:49 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.40 2016/10/13 22:48:51 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -182,34 +182,16 @@ cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist, struct mouse_event *m)
item->mouse.valid = 0;
}
-/* Find hooks list. */
-static struct hooks *
-cmdq_get_hooks(struct cmd_q *cmdq)
-{
- struct session *s;
-
- 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)
- return (s->hooks);
- return (global_hooks);
-}
-
/* Process one command. */
static enum cmd_retval
cmdq_continue_one(struct cmd_q *cmdq)
{
- struct cmd *cmd = cmdq->cmd;
- const char *name = cmd->entry->name;
- struct hooks *hooks;
- enum cmd_retval retval;
- char *tmp;
- int flags = !!(cmd->flags & CMD_CONTROL);
+ struct cmd *cmd = cmdq->cmd;
+ enum cmd_retval retval;
+ char *tmp;
+ int flags = !!(cmd->flags & CMD_CONTROL);
+ const char *name;
+ struct cmd_find_state *fsp, fs;
tmp = cmd_print(cmd);
log_debug("cmdq %p: %s", cmdq, tmp);
@@ -218,44 +200,35 @@ cmdq_continue_one(struct cmd_q *cmdq)
cmdq->time = time(NULL);
cmdq->number++;
- if (~cmdq->flags & CMD_Q_REENTRY)
- cmdq_guard(cmdq, "begin", flags);
+ cmdq_guard(cmdq, "begin", flags);
if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0)
goto error;
- if (~cmdq->flags & CMD_Q_NOHOOKS) {
- hooks = cmdq_get_hooks(cmdq);
- 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) {
- if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0)
- goto error;
- hooks = cmdq_get_hooks(cmdq);
- if (hooks_wait(hooks, cmdq, NULL, "after-%s", name) == 0)
- retval = CMD_RETURN_WAIT;
+ if (~cmd->entry->flags & CMD_AFTERHOOK)
+ goto end;
+
+ if (cmd_find_valid_state(&cmdq->state.tflag))
+ fsp = &cmdq->state.tflag;
+ else {
+ if (cmd_find_current(&fs, cmdq, CMD_FIND_QUIET) != 0)
+ goto end;
+ fsp = &fs;
}
- cmdq_guard(cmdq, "end", flags);
+ name = cmd->entry->name;
+ if (hooks_wait(fsp->s->hooks, cmdq, fsp, "after-%s", name) == 0)
+ retval = CMD_RETURN_WAIT;
+end:
+ cmdq_guard(cmdq, "end", flags);
return (retval);
error:
cmdq_guard(cmdq, "error", flags);
- cmdq->flags &= ~CMD_Q_REENTRY;
return (CMD_RETURN_ERROR);
}
@@ -271,8 +244,6 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->references++;
notify_disable();
- cmd_find_clear_state(&cmdq->current, NULL, 0);
-
log_debug("continuing cmdq %p: flags %#x, client %p", cmdq, cmdq->flags,
c);
@@ -280,18 +251,11 @@ cmdq_continue(struct cmd_q *cmdq)
if (empty)
goto empty;
- /*
- * 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);
- }
+ 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) {