summaryrefslogtreecommitdiffstats
path: root/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm>2019-12-19 09:22:33 +0000
committernicm <nicm>2019-12-19 09:22:33 +0000
commit1764f66b7d1ed0e494cfa8967c78ace8728ee86c (patch)
tree84e6483ab9ec00b4f22e61d764b866562ac6e0d8 /cmd-queue.c
parentef54a08080ef7d721d05361bf10e27217c87590e (diff)
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.
Diffstat (limited to 'cmd-queue.c')
-rw-r--r--cmd-queue.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/cmd-queue.c b/cmd-queue.c
index 69e4f6b2..75b5d8f9 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -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);
}