summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-03-25 11:35:55 +0000
committernicm <nicm@openbsd.org>2013-03-25 11:35:55 +0000
commit0ac894c51c24bafd8a5920f3bb2fb11c2b4e5108 (patch)
tree4b26e10b0c0bd8b43228d4f42e509cc64ba6e2e8 /usr.bin/tmux/cmd-queue.c
parentFix handling of short (< 4 character) checksums and a bug with parsing (diff)
downloadwireguard-openbsd-0ac894c51c24bafd8a5920f3bb2fb11c2b4e5108.tar.xz
wireguard-openbsd-0ac894c51c24bafd8a5920f3bb2fb11c2b4e5108.zip
Add time and a command count to control mode guards, based on code from
George Nachman.
Diffstat (limited to 'usr.bin/tmux/cmd-queue.c')
-rw-r--r--usr.bin/tmux/cmd-queue.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index 88b7162b122..93f607aa382 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.3 2013/03/25 10:06:13 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.4 2013/03/25 11:35:55 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -151,6 +151,22 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
free(msg);
}
+/* Print a guard line. */
+void
+cmdq_guard(struct cmd_q *cmdq, const char *guard)
+{
+ struct client *c = cmdq->client;
+
+ if (c == NULL || c->session == NULL)
+ return;
+ if (!(c->flags & CLIENT_CONTROL))
+ return;
+
+ evbuffer_add_printf(c->stdout_data, "%%%s %ld %u\n", guard,
+ cmdq->time, cmdq->number);
+ server_push_stdout(c);
+}
+
/* Add command list to queue and begin processing if needed. */
void
cmdq_run(struct cmd_q *cmdq, struct cmd_list *cmdlist)
@@ -179,16 +195,11 @@ cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist)
int
cmdq_continue(struct cmd_q *cmdq)
{
- struct client *c = cmdq->client;
struct cmd_q_item *next;
enum cmd_retval retval;
- int guards, empty;
+ int empty;
char s[1024];
- guards = 0;
- if (c != NULL && c->session != NULL)
- guards = c->flags & CLIENT_CONTROL;
-
notify_disable();
empty = TAILQ_EMPTY(&cmdq->queue);
@@ -209,15 +220,15 @@ cmdq_continue(struct cmd_q *cmdq)
log_debug("cmdq %p: %s (client %d)", cmdq, s,
cmdq->client != NULL ? cmdq->client->ibuf.fd : -1);
- if (guards)
- cmdq_print(cmdq, "%%begin");
+ cmdq->time = time(NULL);
+ cmdq->number++;
+
+ cmdq_guard(cmdq, "begin");
retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq);
- if (guards) {
- if (retval == CMD_RETURN_ERROR)
- cmdq_print(cmdq, "%%error");
- else
- cmdq_print(cmdq, "%%end");
- }
+ if (retval == CMD_RETURN_ERROR)
+ cmdq_guard(cmdq, "error");
+ else
+ cmdq_guard(cmdq, "end");
if (retval == CMD_RETURN_ERROR)
break;