summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2019-12-19 09:22:33 +0000
committernicm <nicm@openbsd.org>2019-12-19 09:22:33 +0000
commit95cd24f8dbded881b37e8ba692d540872d4281ec (patch)
tree1f3caee76b89a0a66b0df6f3f31be3e26cada972
parentUse bus_size_t as the type for the base address. (diff)
downloadwireguard-openbsd-95cd24f8dbded881b37e8ba692d540872d4281ec.tar.xz
wireguard-openbsd-95cd24f8dbded881b37e8ba692d540872d4281ec.zip
When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by Jason Kim in GitHub issue 2023.
-rw-r--r--usr.bin/tmux/cfg.c10
-rw-r--r--usr.bin/tmux/cmd-queue.c25
-rw-r--r--usr.bin/tmux/cmd-source-file.c3
-rw-r--r--usr.bin/tmux/key-bindings.c6
-rw-r--r--usr.bin/tmux/notify.c6
-rw-r--r--usr.bin/tmux/tmux.h6
6 files changed, 32 insertions, 24 deletions
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c
index 91d7d9443d5..9a105b49ed8 100644
--- a/usr.bin/tmux/cfg.c
+++ b/usr.bin/tmux/cfg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cfg.c,v 1.77 2019/12/12 12:49:36 nicm Exp $ */
+/* $OpenBSD: cfg.c,v 1.78 2019/12/19 09:22:33 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -185,9 +185,9 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
new_item0 = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
if (item != NULL)
- cmdq_insert_after(item, new_item0);
+ new_item0 = cmdq_insert_after(item, new_item0);
else
- cmdq_append(NULL, new_item0);
+ new_item0 = cmdq_append(NULL, new_item0);
cmd_list_free(pr->cmdlist);
if (new_item != NULL)
@@ -231,9 +231,9 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path,
new_item0 = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
if (item != NULL)
- cmdq_insert_after(item, new_item0);
+ new_item0 = cmdq_insert_after(item, new_item0);
else
- cmdq_append(NULL, new_item0);
+ new_item0 = cmdq_append(NULL, new_item0);
cmd_list_free(pr->cmdlist);
if (new_item != NULL)
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index d03788d6c04..e06a4c0af98 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.77 2019/12/17 11:43:23 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.78 2019/12/19 09:22:33 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -53,12 +53,16 @@ cmdq_get(struct client *c)
}
/* Append an item. */
-void
+struct cmdq_item *
cmdq_append(struct client *c, struct cmdq_item *item)
{
struct cmdq_list *queue = cmdq_get(c);
struct cmdq_item *next;
+ TAILQ_FOREACH(next, queue, entry) {
+ log_debug("%s %s: queue %s (%u)", __func__, cmdq_name(c),
+ next->name, next->group);
+ }
do {
next = item->next;
item->next = NULL;
@@ -73,16 +77,21 @@ cmdq_append(struct client *c, struct cmdq_item *item)
item = next;
} while (item != NULL);
+ return (TAILQ_LAST(queue, cmdq_list));
}
/* Insert an item. */
-void
+struct cmdq_item *
cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
{
struct client *c = after->client;
struct cmdq_list *queue = after->queue;
struct cmdq_item *next;
+ TAILQ_FOREACH(next, queue, entry) {
+ log_debug("%s %s: queue %s (%u)", __func__, cmdq_name(c),
+ next->name, next->group);
+ }
do {
next = item->next;
item->next = after->next;
@@ -100,6 +109,7 @@ cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
after = item;
item = next;
} while (item != NULL);
+ return (after);
}
/* Insert a hook. */
@@ -143,11 +153,10 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
new_item = cmdq_get_command(cmdlist, fs, NULL, CMDQ_NOHOOKS);
cmdq_format(new_item, "hook", "%s", name);
- if (item != NULL) {
- cmdq_insert_after(item, new_item);
- item = new_item;
- } else
- cmdq_append(NULL, new_item);
+ if (item != NULL)
+ item = cmdq_insert_after(item, new_item);
+ else
+ item = cmdq_append(NULL, new_item);
a = options_array_next(a);
}
diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c
index 1295668eee2..43003913d75 100644
--- a/usr.bin/tmux/cmd-source-file.c
+++ b/usr.bin/tmux/cmd-source-file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-source-file.c,v 1.43 2019/12/18 07:48:56 nicm Exp $ */
+/* $OpenBSD: cmd-source-file.c,v 1.44 2019/12/19 09:22:33 nicm Exp $ */
/*
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
@@ -114,6 +114,7 @@ cmd_source_file_done(struct client *c, const char *path, int error,
static void
cmd_source_file_add(struct cmd_source_file_data *cdata, const char *path)
{
+ log_debug("%s: %s", __func__, path);
cdata->files = xreallocarray(cdata->files, cdata->nfiles + 1,
sizeof *cdata->files);
cdata->files[cdata->nfiles++] = xstrdup(path);
diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c
index b7f6a129cbb..9e89186cf9c 100644
--- a/usr.bin/tmux/key-bindings.c
+++ b/usr.bin/tmux/key-bindings.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-bindings.c,v 1.104 2019/12/02 19:25:52 nicm Exp $ */
+/* $OpenBSD: key-bindings.c,v 1.105 2019/12/19 09:22:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -520,8 +520,8 @@ key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
new_item->shared->flags |= CMDQ_SHARED_REPEAT;
}
if (item != NULL)
- cmdq_insert_after(item, new_item);
+ new_item = cmdq_insert_after(item, new_item);
else
- cmdq_append(c, new_item);
+ new_item = cmdq_append(c, new_item);
return (new_item);
}
diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c
index 042163c3f5d..1fbd302e5f8 100644
--- a/usr.bin/tmux/notify.c
+++ b/usr.bin/tmux/notify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: notify.c,v 1.28 2019/05/07 10:25:15 nicm Exp $ */
+/* $OpenBSD: notify.c,v 1.29 2019/12/19 09:22:33 nicm Exp $ */
/*
* Copyright (c) 2012 George Nachman <tmux@georgester.com>
@@ -90,9 +90,7 @@ notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne)
new_item = cmdq_get_command(cmdlist, &fs, NULL, CMDQ_NOHOOKS);
cmdq_format(new_item, "hook", "%s", ne->name);
notify_hook_formats(new_item, s, w, ne->pane);
-
- cmdq_insert_after(item, new_item);
- item = new_item;
+ item = cmdq_insert_after(item, new_item);
a = options_array_next(a);
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index f3424cedc97..b77228dad77 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.941 2019/12/16 16:39:03 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.942 2019/12/19 09:22:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2134,8 +2134,8 @@ struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmd_find_state *,
#define cmdq_get_callback(cb, data) cmdq_get_callback1(#cb, cb, data)
struct cmdq_item *cmdq_get_callback1(const char *, cmdq_cb, void *);
struct cmdq_item *cmdq_get_error(const char *);
-void cmdq_insert_after(struct cmdq_item *, struct cmdq_item *);
-void cmdq_append(struct client *, struct cmdq_item *);
+struct cmdq_item *cmdq_insert_after(struct cmdq_item *, struct cmdq_item *);
+struct cmdq_item *cmdq_append(struct client *, struct cmdq_item *);
void cmdq_insert_hook(struct session *, struct cmdq_item *,
struct cmd_find_state *, const char *, ...);
void cmdq_continue(struct cmdq_item *);