summaryrefslogtreecommitdiffstats
path: root/cmd-source-file.c
diff options
context:
space:
mode:
authornicm <nicm>2016-10-16 17:55:14 +0000
committernicm <nicm>2016-10-16 17:55:14 +0000
commitddc4512d2e0eda6c705e002cb5dbf80719d709e1 (patch)
treecd9ff99f4b1ccb3e76ab99633d59772ae07c3092 /cmd-source-file.c
parentbfe14b531267f3762a518f98b72a3148a134396a (diff)
Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues being dispatched on demand from wherever the command happens to be added, they are now all dispatched from the top level server loop. Command queues may now also include callbacks as well as commands, and items may be inserted after the current command as well as at the end. This all makes command queues significantly more predictable and easier to use, and avoids the complex multiple nested command queues used by source-file, if-shell and friends. A mass rename of struct cmdq to a better name (cmdq_item probably) is coming.
Diffstat (limited to 'cmd-source-file.c')
-rw-r--r--cmd-source-file.c54
1 files changed, 16 insertions, 38 deletions
diff --git a/cmd-source-file.c b/cmd-source-file.c
index 336a79e6..6f9c4451 100644
--- a/cmd-source-file.c
+++ b/cmd-source-file.c
@@ -28,7 +28,7 @@
static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *);
-static void cmd_source_file_done(struct cmd_q *);
+static enum cmd_retval cmd_source_file_done(struct cmd_q *, void *);
const struct cmd_entry cmd_source_file_entry = {
.name = "source-file",
@@ -45,53 +45,31 @@ static enum cmd_retval
cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
- struct cmd_q *cmdq1;
+ struct client *c = cmdq->client;
int quiet;
-
- cmdq1 = cmdq_new(cmdq->client);
- cmdq1->emptyfn = cmd_source_file_done;
- cmdq1->data = cmdq;
+ struct cmd_q *new_cmdq;
quiet = args_has(args, 'q');
- switch (load_cfg(args->argv[0], cmdq1, quiet)) {
+ switch (load_cfg(args->argv[0], c, cmdq, quiet)) {
case -1:
- cmdq_free(cmdq1);
- if (cfg_references == 0) {
+ if (cfg_finished)
cfg_print_causes(cmdq);
- return (CMD_RETURN_ERROR);
- }
- return (CMD_RETURN_NORMAL);
+ return (CMD_RETURN_ERROR);
case 0:
- cmdq_free(cmdq1);
- if (cfg_references == 0)
+ if (cfg_finished)
cfg_print_causes(cmdq);
return (CMD_RETURN_NORMAL);
}
-
- log_debug("%s: cmdq %p, parent %p", __func__, cmdq1, cmdq);
-
- cmdq->references++;
- cfg_references++;
-
- cmdq_continue(cmdq1);
- return (CMD_RETURN_WAIT);
+ if (cfg_finished) {
+ new_cmdq = cmdq_get_callback(cmd_source_file_done, NULL);
+ cmdq_insert_after(cmdq, new_cmdq);
+ }
+ return (CMD_RETURN_NORMAL);
}
-static void
-cmd_source_file_done(struct cmd_q *cmdq1)
+static enum cmd_retval
+cmd_source_file_done(struct cmd_q *cmdq, __unused void *data)
{
- struct cmd_q *cmdq = cmdq1->data;
-
- log_debug("%s: cmdq %p, parent %p", __func__, cmdq1, cmdq);
-
- if (cmdq1->client_exit >= 0)
- cmdq->client_exit = cmdq1->client_exit;
- cmdq_free(cmdq1);
-
- cfg_references--;
- if (cmdq_free(cmdq))
- return;
- if (cfg_references == 0)
- cfg_print_causes(cmdq);
- cmdq_continue(cmdq);
+ cfg_print_causes(cmdq);
+ return (CMD_RETURN_NORMAL);
}