aboutsummaryrefslogtreecommitdiff
path: root/hooks.c
diff options
context:
space:
mode:
Diffstat (limited to 'hooks.c')
-rw-r--r--hooks.c64
1 files changed, 20 insertions, 44 deletions
diff --git a/hooks.c b/hooks.c
index 2e0126b7..cdd2cf45 100644
--- a/hooks.c
+++ b/hooks.c
@@ -33,7 +33,6 @@ RB_GENERATE_STATIC(hooks_tree, hook, entry, hooks_cmp);
static struct hook *hooks_find1(struct hooks *, const char *);
static void hooks_free1(struct hooks *, struct hook *);
-static void hooks_emptyfn(struct cmd_q *);
static int
hooks_cmp(struct hook *hook1, struct hook *hook2)
@@ -140,28 +139,14 @@ hooks_find(struct hooks *hooks, const char *name)
return (hook);
}
-static void
-hooks_emptyfn(struct cmd_q *hooks_cmdq)
-{
- struct cmd_q *cmdq = hooks_cmdq->data;
-
- if (cmdq != NULL) {
- if (hooks_cmdq->client_exit >= 0)
- cmdq->client_exit = hooks_cmdq->client_exit;
- if (!cmdq_free(cmdq))
- cmdq_continue(cmdq);
- }
- cmdq_free(hooks_cmdq);
-}
-
-int
+void
hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs,
const char *fmt, ...)
{
struct hook *hook;
- struct cmd_q *hooks_cmdq;
va_list ap;
char *name;
+ struct cmd_q *new_cmdq, *loop;
va_start(ap, fmt);
xvasprintf(&name, fmt, ap);
@@ -170,34 +155,30 @@ hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs,
hook = hooks_find(hooks, name);
if (hook == NULL) {
free(name);
- return (-1);
+ return;
}
log_debug("running hook %s", name);
- free(name);
- hooks_cmdq = cmdq_new(c);
- hooks_cmdq->flags |= CMD_Q_NOHOOKS;
+ new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS);
- if (fs != NULL)
- cmd_find_copy_state(&hooks_cmdq->current, fs);
- hooks_cmdq->parent = NULL;
+ for (loop = new_cmdq; loop != NULL; loop = loop->next)
+ loop->hook = xstrdup(name);
+ free(name);
- cmdq_run(hooks_cmdq, hook->cmdlist, NULL);
- cmdq_free(hooks_cmdq);
- return (0);
+ cmdq_append(c, new_cmdq);
}
-int
-hooks_wait(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs,
+void
+hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs,
const char *fmt, ...)
{
struct hook *hook;
- struct cmd_q *hooks_cmdq;
va_list ap;
char *name;
+ struct cmd_q *new_cmdq, *loop;
if (cmdq->flags & CMD_Q_NOHOOKS)
- return (-1);
+ return;
va_start(ap, fmt);
xvasprintf(&name, fmt, ap);
@@ -206,23 +187,18 @@ hooks_wait(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs,
hook = hooks_find(hooks, name);
if (hook == NULL) {
free(name);
- return (-1);
+ return;
}
log_debug("running hook %s (parent %p)", name, cmdq);
- free(name);
-
- hooks_cmdq = cmdq_new(cmdq->client);
- hooks_cmdq->flags |= CMD_Q_NOHOOKS;
- if (fs != NULL)
- cmd_find_copy_state(&hooks_cmdq->current, fs);
- hooks_cmdq->parent = cmdq;
+ new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS);
- hooks_cmdq->emptyfn = hooks_emptyfn;
- hooks_cmdq->data = cmdq;
+ for (loop = new_cmdq; loop != NULL; loop = loop->next)
+ loop->hook = xstrdup(name);
+ free(name);
if (cmdq != NULL)
- cmdq->references++;
- cmdq_run(hooks_cmdq, hook->cmdlist, NULL);
- return (0);
+ cmdq_insert_after(cmdq, new_cmdq);
+ else
+ cmdq_append(NULL, new_cmdq);
}