Annotation of src/usr.bin/tmux/cmd-server-info.c, Revision 1.34
1.34 ! nicm 1: /* $OpenBSD: cmd-server-info.c,v 1.33 2013/03/25 10:11:45 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2008 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: #include <sys/utsname.h>
21:
22: #include <stdlib.h>
23: #include <string.h>
24: #include <time.h>
25: #include <unistd.h>
1.2 nicm 26: #include <vis.h>
1.1 nicm 27:
28: #include "tmux.h"
29:
30: /*
31: * Show various information about server.
32: */
33:
1.32 nicm 34: enum cmd_retval cmd_server_info_exec(struct cmd *, struct cmd_q *);
1.1 nicm 35:
36: const struct cmd_entry cmd_server_info_entry = {
37: "server-info", "info",
1.21 nicm 38: "", 0, 0,
1.1 nicm 39: "",
1.21 nicm 40: 0,
1.1 nicm 41: NULL,
1.21 nicm 42: cmd_server_info_exec
1.1 nicm 43: };
44:
1.27 nicm 45: enum cmd_retval
1.32 nicm 46: cmd_server_info_exec(unused struct cmd *self, struct cmd_q *cmdq)
1.1 nicm 47: {
1.20 nicm 48: struct tty_term *term;
49: struct client *c;
50: struct session *s;
51: struct winlink *wl;
52: struct window *w;
53: struct window_pane *wp;
54: struct tty_code *code;
55: const struct tty_term_code_entry *ent;
56: struct utsname un;
57: struct job *job;
58: struct grid *gd;
59: struct grid_line *gl;
1.30 nicm 60: u_int i, j, k, lines;
61: size_t size;
1.20 nicm 62: char out[80];
63: char *tim;
64: time_t t;
1.1 nicm 65:
66: tim = ctime(&start_time);
67: *strchr(tim, '\n') = '\0';
1.32 nicm 68: cmdq_print(cmdq, "pid %ld, started %s", (long) getpid(), tim);
69: cmdq_print(cmdq, "socket path %s, debug level %d", socket_path,
70: debug_level);
1.25 matthew 71: if (uname(&un) >= 0) {
1.32 nicm 72: cmdq_print(cmdq, "system is %s %s %s %s",
1.1 nicm 73: un.sysname, un.release, un.version, un.machine);
74: }
75: if (cfg_file != NULL)
1.32 nicm 76: cmdq_print(cmdq, "configuration file is %s", cfg_file);
1.1 nicm 77: else
1.32 nicm 78: cmdq_print(cmdq, "configuration file not specified");
79: cmdq_print(cmdq, "protocol version is %d", PROTOCOL_VERSION);
80: cmdq_print(cmdq, "%s", "");
1.1 nicm 81:
1.32 nicm 82: cmdq_print(cmdq, "Clients:");
1.1 nicm 83: for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
84: c = ARRAY_ITEM(&clients, i);
85: if (c == NULL || c->session == NULL)
86: continue;
87:
1.32 nicm 88: cmdq_print(cmdq,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
1.28 nicm 89: "class=%u] [flags=0x%x/0x%x, references=%u]", i,
1.26 nicm 90: c->tty.path, c->ibuf.fd, c->tty.fd, c->session->name,
1.22 nicm 91: c->tty.sx, c->tty.sy, c->tty.termname,
1.29 nicm 92: c->tty.tio.c_cc[VERASE], c->tty.class,
1.26 nicm 93: c->flags, c->tty.flags, c->references);
1.1 nicm 94: }
1.32 nicm 95: cmdq_print(cmdq, "%s", "");
1.1 nicm 96:
1.32 nicm 97: cmdq_print(cmdq, "Sessions: [%zu]", sizeof (struct grid_cell));
1.19 nicm 98: RB_FOREACH(s, sessions, &sessions) {
1.14 nicm 99: t = s->creation_time.tv_sec;
1.1 nicm 100: tim = ctime(&t);
101: *strchr(tim, '\n') = '\0';
102:
1.32 nicm 103: cmdq_print(cmdq, "%2u: %s: %u windows (created %s) [%ux%u] "
1.33 nicm 104: "[flags=0x%x]", s->id, s->name,
1.19 nicm 105: winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
1.1 nicm 106: RB_FOREACH(wl, winlinks, &s->windows) {
107: w = wl->window;
1.32 nicm 108: cmdq_print(cmdq, "%4u: %s [%ux%u] [flags=0x%x, "
1.5 nicm 109: "references=%u, last layout=%d]", wl->idx, w->name,
1.1 nicm 110: w->sx, w->sy, w->flags, w->references,
1.5 nicm 111: w->lastlayout);
1.1 nicm 112: j = 0;
113: TAILQ_FOREACH(wp, &w->panes, entry) {
1.30 nicm 114: lines = size = 0;
1.1 nicm 115: gd = wp->base.grid;
116: for (k = 0; k < gd->hsize + gd->sy; k++) {
1.6 nicm 117: gl = &gd->linedata[k];
1.30 nicm 118: if (gl->celldata == NULL)
119: continue;
120: lines++;
121: size += gl->cellsize *
122: sizeof *gl->celldata;
1.1 nicm 123: }
1.32 nicm 124: cmdq_print(cmdq,
1.30 nicm 125: "%6u: %s %lu %d %u/%u, %zu bytes", j,
1.1 nicm 126: wp->tty, (u_long) wp->pid, wp->fd, lines,
1.30 nicm 127: gd->hsize + gd->sy, size);
1.1 nicm 128: j++;
129: }
130: }
131: }
1.32 nicm 132: cmdq_print(cmdq, "%s", "");
1.1 nicm 133:
1.32 nicm 134: cmdq_print(cmdq, "Terminals:");
1.23 nicm 135: LIST_FOREACH(term, &tty_terms, entry) {
1.32 nicm 136: cmdq_print(cmdq, "%s [references=%u, flags=0x%x]:",
1.1 nicm 137: term->name, term->references, term->flags);
138: for (i = 0; i < NTTYCODE; i++) {
139: ent = &tty_term_codes[i];
140: code = &term->codes[ent->code];
141: switch (code->type) {
142: case TTYCODE_NONE:
1.32 nicm 143: cmdq_print(cmdq, "%2u: %s: [missing]",
1.1 nicm 144: ent->code, ent->name);
145: break;
146: case TTYCODE_STRING:
1.2 nicm 147: strnvis(out, code->value.string, sizeof out,
148: VIS_OCTAL|VIS_TAB|VIS_NL);
1.32 nicm 149: cmdq_print(cmdq, "%2u: %s: (string) %s",
1.1 nicm 150: ent->code, ent->name, out);
151: break;
152: case TTYCODE_NUMBER:
1.32 nicm 153: cmdq_print(cmdq, "%2u: %s: (number) %d",
1.1 nicm 154: ent->code, ent->name, code->value.number);
155: break;
156: case TTYCODE_FLAG:
1.32 nicm 157: cmdq_print(cmdq, "%2u: %s: (flag) %s",
1.1 nicm 158: ent->code, ent->name,
159: code->value.flag ? "true" : "false");
160: break;
161: }
162: }
163: }
1.32 nicm 164: cmdq_print(cmdq, "%s", "");
1.13 nicm 165:
1.32 nicm 166: cmdq_print(cmdq, "Jobs:");
1.23 nicm 167: LIST_FOREACH(job, &all_jobs, lentry) {
1.32 nicm 168: cmdq_print(cmdq, "%s [fd=%d, pid=%d, status=%d]",
1.24 nicm 169: job->cmd, job->fd, job->pid, job->status);
1.13 nicm 170: }
1.1 nicm 171:
1.27 nicm 172: return (CMD_RETURN_NORMAL);
1.1 nicm 173: }