diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-05-16 15:47:23 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-05-16 15:47:23 +0000 |
commit | 151ea8f0307cd52674598662671bc04e48455589 (patch) | |
tree | d0ec71794c18dc0f2e22b4685af5968159c71d92 /usr.bin | |
parent | 92385533c889a9f2e4b5fe846ef83ceb9b849019 (diff) |
Change message log to be per server rather than per client and include
every command that is run.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-queue.c | 27 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-show-messages.c | 20 | ||||
-rw-r--r-- | usr.bin/tmux/format.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/options-table.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/server-client.c | 51 | ||||
-rw-r--r-- | usr.bin/tmux/server.c | 37 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 11 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 20 |
9 files changed, 97 insertions, 83 deletions
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c index a1f8564534f..f4e5a3a5b13 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.92 2020/05/16 15:40:04 nicm Exp $ */ +/* $OpenBSD: cmd-queue.c,v 1.93 2020/05/16 15:47:22 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -534,6 +534,28 @@ cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs, return (CMD_RETURN_NORMAL); } +/* Add message with command. */ +static void +cmdq_add_message(struct cmdq_item *item) +{ + struct client *c = item->client; + struct cmdq_state *state = item->state; + const char *name, *key; + char *tmp; + + tmp = cmd_print(item->cmd); + if (c != NULL) { + name = c->name; + if (c->session != NULL && state->event.key != KEYC_NONE) { + key = key_string_lookup_key(state->event.key); + server_add_message("%s key %s: %s", name, key, tmp); + } else + server_add_message("%s command: %s", name, tmp); + } else + server_add_message("command: %s", tmp); + free(tmp); +} + /* Fire command on command queue. */ static enum cmd_retval cmdq_fire_command(struct cmdq_item *item) @@ -549,6 +571,8 @@ cmdq_fire_command(struct cmdq_item *item) int flags, quiet = 0; char *tmp; + if (cfg_finished) + cmdq_add_message(item); if (log_get_level() > 1) { tmp = cmd_print(cmd); log_debug("%s %s: (%u) %s", __func__, name, item->group, tmp); @@ -819,6 +843,7 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...) cmd_get_source(cmd, &file, &line); cfg_add_cause("%s:%u: %s", file, line, msg); } else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) { + server_add_message("%s message: %s", c->name, msg); if (~c->flags & CLIENT_UTF8) { tmp = msg; msg = utf8_sanitize(tmp); diff --git a/usr.bin/tmux/cmd-show-messages.c b/usr.bin/tmux/cmd-show-messages.c index 2d832e6f412..9dbb39fa248 100644 --- a/usr.bin/tmux/cmd-show-messages.c +++ b/usr.bin/tmux/cmd-show-messages.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-show-messages.c,v 1.32 2020/04/20 13:25:36 nicm Exp $ */ +/* $OpenBSD: cmd-show-messages.c,v 1.33 2020/05/16 15:47:22 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -72,10 +72,10 @@ static enum cmd_retval cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct client *tc = cmdq_get_target_client(item); struct message_entry *msg; - char *tim; + char *s; int done, blank; + struct format_tree *ft; done = blank = 0; if (args_has(args, 'T')) { @@ -89,11 +89,17 @@ cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item) if (done) return (CMD_RETURN_NORMAL); - TAILQ_FOREACH(msg, &tc->message_log, entry) { - tim = ctime(&msg->msg_time); - *strchr(tim, '\n') = '\0'; - cmdq_print(item, "%s %s", tim, msg->msg); + ft = format_create_from_target(item); + TAILQ_FOREACH_REVERSE(msg, &message_log, message_list, entry) { + format_add(ft, "message_text", "%s", msg->msg); + format_add(ft, "message_number", "%u", msg->msg_num); + format_add_tv(ft, "message_time", &msg->msg_time); + + s = format_expand(ft, SHOW_MESSAGES_TEMPLATE); + cmdq_print(item, "%s", s); + free(s); } + format_free(ft); return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 963afe6da27..37d6b74799c 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.252 2020/05/16 15:45:29 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.253 2020/05/16 15:47:22 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -46,8 +46,6 @@ static void format_job_timer(int, short, void *); static char *format_find(struct format_tree *, const char *, int); static void format_add_cb(struct format_tree *, const char *, format_cb); -static void format_add_tv(struct format_tree *, const char *, - struct timeval *); static int format_replace(struct format_tree *, const char *, size_t, char **, size_t *, size_t *); static void format_defaults_session(struct format_tree *, @@ -1260,7 +1258,7 @@ format_add(struct format_tree *ft, const char *key, const char *fmt, ...) } /* Add a key and time. */ -static void +void format_add_tv(struct format_tree *ft, const char *key, struct timeval *tv) { struct format_entry *fe, *fe_now; diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index 5295113e0e5..0a55720e0f6 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.125 2020/05/16 15:24:28 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.126 2020/05/16 15:47:22 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -253,7 +253,7 @@ const struct options_table_entry options_table[] = { .scope = OPTIONS_TABLE_SERVER, .minimum = 0, .maximum = INT_MAX, - .default_num = 100 + .default_num = 1000 }, { .name = "set-clipboard", diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index ae57ff40061..21454a9ad10 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.337 2020/05/16 15:45:29 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.338 2020/05/16 15:47:22 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -213,23 +213,12 @@ server_client_create(int fd) c->queue = cmdq_new(); c->tty.fd = -1; - c->title = NULL; - - c->session = NULL; - c->last_session = NULL; c->tty.sx = 80; c->tty.sy = 24; status_init(c); - c->message_string = NULL; - TAILQ_INIT(&c->message_log); - - c->prompt_string = NULL; - c->prompt_buffer = NULL; - c->prompt_index = 0; - RB_INIT(&c->files); c->flags |= CLIENT_FOCUSED; @@ -272,7 +261,6 @@ server_client_open(struct client *c, char **cause) void server_client_lost(struct client *c) { - struct message_entry *msg, *msg1; struct client_file *cf; c->flags |= CLIENT_DEAD; @@ -313,11 +301,6 @@ server_client_lost(struct client *c) free(c->message_string); if (event_initialized(&c->message_timer)) evtimer_del(&c->message_timer); - TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) { - free(msg->msg); - TAILQ_REMOVE(&c->message_log, msg, entry); - free(msg); - } free(c->prompt_saved); free(c->prompt_string); @@ -1128,6 +1111,7 @@ server_client_key_callback(struct cmdq_item *item, void *data) c->tty.mouse_drag_update(c, m); goto out; } + event->key = key; } /* Find affected pane. */ @@ -2204,37 +2188,6 @@ server_client_dispatch_read_done(struct client *c, struct imsg *imsg) file_fire_done(cf); } -/* Add to client message log. */ -void -server_client_add_message(struct client *c, 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 (client %p)", s, c); - - msg = xcalloc(1, sizeof *msg); - msg->msg_time = time(NULL); - msg->msg_num = c->message_next++; - msg->msg = s; - TAILQ_INSERT_TAIL(&c->message_log, msg, entry); - - limit = options_get_number(global_options, "message-limit"); - TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) { - if (msg->msg_num + limit >= c->message_next) - break; - free(msg->msg); - TAILQ_REMOVE(&c->message_log, msg, entry); - free(msg); - } -} - /* Get client working directory. */ const char * server_client_get_cwd(struct client *c, struct session *s) 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); + } +} diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index ddcd9d7915f..3e0f0157af0 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.208 2020/05/16 15:34:08 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.209 2020/05/16 15:47:22 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -436,7 +436,7 @@ status_message_set(struct client *c, const char *fmt, ...) xvasprintf(&c->message_string, fmt, ap); va_end(ap); - server_client_add_message(c, "%s", c->message_string); + server_add_message("%s message: %s", c->name, c->message_string); delay = options_get_number(c->session->options, "display-time"); if (delay > 0) { diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index f9825caa29e..81a3dad64df 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.763 2020/05/16 15:46:01 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.764 2020/05/16 15:47:22 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -1311,15 +1311,10 @@ Rename the session to .Op Fl t Ar target-client .Xc .D1 (alias: Ic showmsgs ) -Show client messages or server information. -Any messages displayed on the status line are saved in a per-client message -log, up to a maximum of the limit set by the +Show server messages or information. +Messages are stored, up to a maximum of the limit set by the .Ar message-limit server option. -With -.Fl t , -display the log for -.Ar target-client . .Fl J and .Fl T diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 21299473f4c..426025f92f7 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1033 2020/05/16 15:45:29 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1034 2020/05/16 15:47:22 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1341,11 +1341,13 @@ struct tty_ctx { /* Saved message entry. */ struct message_entry { - char *msg; - u_int msg_num; - time_t msg_time; - TAILQ_ENTRY(message_entry) entry; + char *msg; + u_int msg_num; + struct timeval msg_time; + + TAILQ_ENTRY(message_entry) entry; }; +TAILQ_HEAD(message_list, message_entry); /* Parsed arguments structures. */ struct args_entry; @@ -1603,8 +1605,6 @@ struct client { char *message_string; struct event message_timer; - u_int message_next; - TAILQ_HEAD(, message_entry) message_log; char *prompt_string; struct utf8_data *prompt_buffer; @@ -1846,6 +1846,8 @@ void format_free(struct format_tree *); void format_merge(struct format_tree *, struct format_tree *); void printflike(3, 4) format_add(struct format_tree *, const char *, const char *, ...); +void format_add_tv(struct format_tree *, const char *, + struct timeval *); void format_each(struct format_tree *, void (*)(const char *, const char *, void *), void *); char *format_expand_time(struct format_tree *, const char *); @@ -2269,6 +2271,7 @@ void file_push(struct client_file *); extern struct tmuxproc *server_proc; extern struct clients clients; extern struct cmd_find_state marked_pane; +extern struct message_list message_log; void server_set_marked(struct session *, struct winlink *, struct window_pane *); void server_clear_marked(void); @@ -2278,6 +2281,7 @@ int server_check_marked(void); int server_start(struct tmuxproc *, int, struct event_base *, int, char *); void server_update_socket(void); void server_add_accept(int); +void printflike(1, 2) server_add_message(const char *, ...); /* server-client.c */ u_int server_client_how_many(void); @@ -2299,8 +2303,6 @@ void server_client_exec(struct client *, const char *); void server_client_loop(void); void server_client_push_stdout(struct client *); void server_client_push_stderr(struct client *); -void printflike(2, 3) server_client_add_message(struct client *, const char *, - ...); const char *server_client_get_cwd(struct client *, struct session *); void server_client_set_flags(struct client *, const char *); const char *server_client_get_flags(struct client *); |