summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/server.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-05-16 15:47:23 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-05-16 15:47:23 +0000
commit151ea8f0307cd52674598662671bc04e48455589 (patch)
treed0ec71794c18dc0f2e22b4685af5968159c71d92 /usr.bin/tmux/server.c
parent92385533c889a9f2e4b5fe846ef83ceb9b849019 (diff)
Change message log to be per server rather than per client and include
every command that is run.
Diffstat (limited to 'usr.bin/tmux/server.c')
-rw-r--r--usr.bin/tmux/server.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 28dcccc6695..842bc7fd346 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.189 2020/05/16 15:24:28 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.190 2020/05/16 15:47:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -51,6 +51,9 @@ static struct event server_ev_accept;
struct cmd_find_state marked_pane;
+static u_int message_next;
+struct message_list message_log;
+
static int server_loop(void);
static void server_send_exit(void);
static void server_accept(int, short, void *);
@@ -195,6 +198,7 @@ server_start(struct tmuxproc *client, int flags, struct event_base *base,
TAILQ_INIT(&clients);
RB_INIT(&sessions);
key_bindings_init();
+ TAILQ_INIT(&message_log);
gettimeofday(&start_time, NULL);
@@ -483,3 +487,34 @@ server_child_stopped(pid_t pid, int status)
}
job_check_died(pid, status);
}
+
+/* Add to message log. */
+void
+server_add_message(const char *fmt, ...)
+{
+ struct message_entry *msg, *msg1;
+ char *s;
+ va_list ap;
+ u_int limit;
+
+ va_start(ap, fmt);
+ xvasprintf(&s, fmt, ap);
+ va_end(ap);
+
+ log_debug("message: %s", s);
+
+ msg = xcalloc(1, sizeof *msg);
+ gettimeofday(&msg->msg_time, NULL);
+ msg->msg_num = message_next++;
+ msg->msg = s;
+ TAILQ_INSERT_TAIL(&message_log, msg, entry);
+
+ limit = options_get_number(global_options, "message-limit");
+ TAILQ_FOREACH_SAFE(msg, &message_log, entry, msg1) {
+ if (msg->msg_num + limit >= message_next)
+ break;
+ free(msg->msg);
+ TAILQ_REMOVE(&message_log, msg, entry);
+ free(msg);
+ }
+}