aboutsummaryrefslogtreecommitdiff
path: root/cmd-queue.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-queue.c')
-rw-r--r--cmd-queue.c72
1 files changed, 17 insertions, 55 deletions
diff --git a/cmd-queue.c b/cmd-queue.c
index 17955b82..58282c8f 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $OpenBSD$ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -57,7 +57,7 @@ cmdq_free(struct cmd_q *cmdq)
}
/* Show message from command. */
-void printflike2
+void
cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
@@ -86,55 +86,23 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
va_end(ap);
}
-/* Show info from command. */
-void printflike2
-cmdq_info(struct cmd_q *cmdq, const char *fmt, ...)
-{
- struct client *c = cmdq->client;
- va_list ap;
- char *msg;
-
- if (options_get_number(&global_options, "quiet"))
- return;
-
- va_start(ap, fmt);
-
- if (c == NULL)
- /* nothing */;
- else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
- evbuffer_add_vprintf(c->stdout_data, fmt, ap);
-
- evbuffer_add(c->stdout_data, "\n", 1);
- server_push_stdout(c);
- } else {
- xvasprintf(&msg, fmt, ap);
- *msg = toupper((u_char) *msg);
- status_message_set(c, "%s", msg);
- free(msg);
- }
-
- va_end(ap);
-
-}
-
/* Show error from command. */
-void printflike2
+void
cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
struct cmd *cmd = cmdq->cmd;
va_list ap;
- char *msg, *cause;
+ char *msg;
size_t msglen;
va_start(ap, fmt);
msglen = xvasprintf(&msg, fmt, ap);
va_end(ap);
- if (c == NULL) {
- xasprintf(&cause, "%s:%u: %s", cmd->file, cmd->line, msg);
- ARRAY_ADD(&cfg_causes, cause);
- } else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
+ if (c == NULL)
+ cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg);
+ else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
evbuffer_add(c->stderr_data, msg, msglen);
evbuffer_add(c->stderr_data, "\n", 1);
@@ -149,20 +117,17 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
}
/* Print a guard line. */
-int
+void
cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags)
{
struct client *c = cmdq->client;
- if (c == NULL)
- return 0;
- if (!(c->flags & CLIENT_CONTROL))
- return 0;
+ if (c == NULL || !(c->flags & CLIENT_CONTROL))
+ return;
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
(long) cmdq->time, cmdq->number, flags);
server_push_stdout(c);
- return 1;
}
/* Add command list to queue and begin processing if needed. */
@@ -195,7 +160,7 @@ cmdq_continue(struct cmd_q *cmdq)
{
struct cmd_q_item *next;
enum cmd_retval retval;
- int empty, guard, flags;
+ int empty, flags;
char s[1024];
notify_disable();
@@ -211,8 +176,6 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
do {
- next = TAILQ_NEXT(cmdq->item, qentry);
-
while (cmdq->cmd != NULL) {
cmd_print(cmdq->cmd, s, sizeof s);
log_debug("cmdq %p: %s (client %d)", cmdq, s,
@@ -222,16 +185,14 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->number++;
flags = !!(cmdq->cmd->flags & CMD_CONTROL);
- guard = cmdq_guard(cmdq, "begin", flags);
+ cmdq_guard(cmdq, "begin", flags);
retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq);
- if (guard) {
- if (retval == CMD_RETURN_ERROR)
- cmdq_guard(cmdq, "error", flags);
- else
- cmdq_guard(cmdq, "end", flags);
- }
+ if (retval == CMD_RETURN_ERROR)
+ cmdq_guard(cmdq, "error", flags);
+ else
+ cmdq_guard(cmdq, "end", flags);
if (retval == CMD_RETURN_ERROR)
break;
@@ -244,6 +205,7 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
}
+ next = TAILQ_NEXT(cmdq->item, qentry);
TAILQ_REMOVE(&cmdq->queue, cmdq->item, qentry);
cmd_list_free(cmdq->item->cmdlist);