Annotation of src/usr.bin/tmux/cmd-show-messages.c, Revision 1.15
1.15 ! nicm 1: /* $OpenBSD: cmd-show-messages.c,v 1.14 2015/11/24 21:19:46 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15: * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <sys/types.h>
20:
21: #include <string.h>
22: #include <time.h>
1.8 nicm 23: #include <unistd.h>
24: #include <vis.h>
1.1 nicm 25:
26: #include "tmux.h"
27:
28: /*
29: * Show client message log.
30: */
31:
1.6 nicm 32: enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *);
1.1 nicm 33:
34: const struct cmd_entry cmd_show_messages_entry = {
35: "show-messages", "showmsgs",
1.8 nicm 36: "IJTt:", 0, 0,
37: "[-IJT] " CMD_TARGET_CLIENT_USAGE,
1.3 nicm 38: 0,
39: cmd_show_messages_exec
1.1 nicm 40: };
41:
1.8 nicm 42: const struct cmd_entry cmd_server_info_entry = {
43: "server-info", "info",
44: "", 0, 0,
45: "",
46: 0,
47: cmd_show_messages_exec
48: };
49:
1.12 nicm 50: int cmd_show_messages_server(struct cmd_q *);
51: int cmd_show_messages_terminals(struct cmd_q *, int);
52: int cmd_show_messages_jobs(struct cmd_q *, int);
1.8 nicm 53:
1.12 nicm 54: int
1.9 nicm 55: cmd_show_messages_server(struct cmd_q *cmdq)
1.8 nicm 56: {
57: char *tim;
58:
59: tim = ctime(&start_time);
60: *strchr(tim, '\n') = '\0';
61:
62: cmdq_print(cmdq, "started %s", tim);
63: cmdq_print(cmdq, "socket path %s", socket_path);
64: cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION);
1.15 ! nicm 65: cmdq_print(cmdq, "libevent %s (%s)", event_get_version(),
! 66: event_get_method());
1.12 nicm 67:
68: return (1);
1.8 nicm 69: }
70:
1.12 nicm 71: int
72: cmd_show_messages_terminals(struct cmd_q *cmdq, int blank)
1.8 nicm 73: {
1.13 nicm 74: struct tty_term *term;
75: u_int i, n;
1.8 nicm 76:
77: n = 0;
78: LIST_FOREACH(term, &tty_terms, entry) {
1.12 nicm 79: if (blank) {
80: cmdq_print(cmdq, "%s", "");
81: blank = 0;
82: }
83: cmdq_print(cmdq, "Terminal %u: %s [references=%u, flags=0x%x]:",
1.8 nicm 84: n, term->name, term->references, term->flags);
85: n++;
1.13 nicm 86: for (i = 0; i < tty_term_ncodes(); i++)
87: cmdq_print(cmdq, "%s", tty_term_describe(term, i));
1.8 nicm 88: }
1.12 nicm 89: return (n != 0);
1.8 nicm 90: }
91:
1.12 nicm 92: int
93: cmd_show_messages_jobs(struct cmd_q *cmdq, int blank)
1.8 nicm 94: {
95: struct job *job;
96: u_int n;
97:
98: n = 0;
99: LIST_FOREACH(job, &all_jobs, lentry) {
1.12 nicm 100: if (blank) {
101: cmdq_print(cmdq, "%s", "");
102: blank = 0;
103: }
104: cmdq_print(cmdq, "Job %u: %s [fd=%d, pid=%d, status=%d]",
1.8 nicm 105: n, job->cmd, job->fd, job->pid, job->status);
106: n++;
107: }
1.12 nicm 108: return (n != 0);
1.8 nicm 109: }
110:
1.4 nicm 111: enum cmd_retval
1.6 nicm 112: cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
1.1 nicm 113: {
1.3 nicm 114: struct args *args = self->args;
115: struct client *c;
116: struct message_entry *msg;
117: char *tim;
1.12 nicm 118: int done, blank;
1.8 nicm 119:
1.12 nicm 120: done = blank = 0;
1.9 nicm 121: if (args_has(args, 'I') || self->entry == &cmd_server_info_entry) {
1.12 nicm 122: blank = cmd_show_messages_server(cmdq);
1.8 nicm 123: done = 1;
124: }
1.9 nicm 125: if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) {
1.12 nicm 126: blank = cmd_show_messages_terminals(cmdq, blank);
1.8 nicm 127: done = 1;
128: }
1.9 nicm 129: if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) {
1.12 nicm 130: cmd_show_messages_jobs(cmdq, blank);
1.8 nicm 131: done = 1;
132: }
133: if (done)
134: return (CMD_RETURN_NORMAL);
1.1 nicm 135:
1.6 nicm 136: if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
1.4 nicm 137: return (CMD_RETURN_ERROR);
1.1 nicm 138:
1.11 nicm 139: TAILQ_FOREACH(msg, &c->message_log, entry) {
1.1 nicm 140: tim = ctime(&msg->msg_time);
141: *strchr(tim, '\n') = '\0';
1.2 nicm 142:
1.6 nicm 143: cmdq_print(cmdq, "%s %s", tim, msg->msg);
1.1 nicm 144: }
145:
1.4 nicm 146: return (CMD_RETURN_NORMAL);
1.1 nicm 147: }