cmd-show-messages.c revision 1.2
1/* Id */ 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> 23#include <unistd.h> 24 25#include "tmux.h" 26 27/* 28 * Show client message log. 29 */ 30 31enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *); 32 33const struct cmd_entry cmd_show_messages_entry = { 34 "show-messages", "showmsgs", 35 "IJTt:", 0, 0, 36 "[-IJT] " CMD_TARGET_CLIENT_USAGE, 37 0, 38 NULL, 39 cmd_show_messages_exec 40}; 41 42const struct cmd_entry cmd_server_info_entry = { 43 "server-info", "info", 44 "", 0, 0, 45 "", 46 0, 47 NULL, 48 cmd_show_messages_exec 49}; 50 51void cmd_show_messages_server(struct cmd_q *); 52void cmd_show_messages_terminals(struct cmd_q *); 53void cmd_show_messages_jobs(struct cmd_q *); 54 55void 56cmd_show_messages_server(struct cmd_q *cmdq) 57{ 58 char *tim; 59 60 tim = ctime(&start_time); 61 *strchr(tim, '\n') = '\0'; 62 63 cmdq_print(cmdq, "started %s", tim); 64 cmdq_print(cmdq, "socket path %s", socket_path); 65 cmdq_print(cmdq, "debug level %d", debug_level); 66 cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION); 67} 68 69void 70cmd_show_messages_terminals(struct cmd_q *cmdq) 71{ 72 struct tty_term *term; 73 const struct tty_term_code_entry *ent; 74 struct tty_code *code; 75 u_int i, n; 76 char out[80]; 77 78 n = 0; 79 LIST_FOREACH(term, &tty_terms, entry) { 80 cmdq_print(cmdq, 81 "Terminal %u: %s [references=%u, flags=0x%x]:", 82 n, term->name, term->references, term->flags); 83 n++; 84 for (i = 0; i < NTTYCODE; i++) { 85 ent = &tty_term_codes[i]; 86 code = &term->codes[ent->code]; 87 switch (code->type) { 88 case TTYCODE_NONE: 89 cmdq_print(cmdq, "%4u: %s: [missing]", 90 ent->code, ent->name); 91 break; 92 case TTYCODE_STRING: 93 strnvis(out, sizeof out, code->value.string, 94 VIS_OCTAL|VIS_TAB|VIS_NL); 95 cmdq_print(cmdq, "%4u: %s: (string) %s", 96 ent->code, ent->name, out); 97 break; 98 case TTYCODE_NUMBER: 99 cmdq_print(cmdq, "%4u: %s: (number) %d", 100 ent->code, ent->name, code->value.number); 101 break; 102 case TTYCODE_FLAG: 103 cmdq_print(cmdq, "%4u: %s: (flag) %s", 104 ent->code, ent->name, 105 code->value.flag ? "true" : "false"); 106 break; 107 } 108 } 109 } 110} 111 112void 113cmd_show_messages_jobs(struct cmd_q *cmdq) 114{ 115 struct job *job; 116 u_int n; 117 118 n = 0; 119 LIST_FOREACH(job, &all_jobs, lentry) { 120 cmdq_print(cmdq, 121 "Job %u: %s [fd=%d, pid=%d, status=%d]", 122 n, job->cmd, job->fd, job->pid, job->status); 123 n++; 124 } 125} 126 127enum cmd_retval 128cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq) 129{ 130 struct args *args = self->args; 131 struct client *c; 132 struct message_entry *msg; 133 char *tim; 134 u_int i; 135 int done; 136 137 done = 0; 138 if (args_has(args, 'I') || self->entry == &cmd_server_info_entry) { 139 cmd_show_messages_server(cmdq); 140 done = 1; 141 } 142 if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) { 143 if (done) 144 cmdq_print(cmdq, "%s", ""); 145 cmd_show_messages_terminals(cmdq); 146 done = 1; 147 } 148 if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) { 149 if (done) 150 cmdq_print(cmdq, "%s", ""); 151 cmd_show_messages_jobs(cmdq); 152 done = 1; 153 } 154 if (done) 155 return (CMD_RETURN_NORMAL); 156 157 if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL) 158 return (CMD_RETURN_ERROR); 159 160 for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) { 161 msg = &ARRAY_ITEM(&c->message_log, i); 162 163 tim = ctime(&msg->msg_time); 164 *strchr(tim, '\n') = '\0'; 165 166 cmdq_print(cmdq, "%s %s", tim, msg->msg); 167 } 168 169 return (CMD_RETURN_NORMAL); 170} 171