Annotation of src/usr.bin/tmux/cmd-server-info.c, Revision 1.5
1.5 ! nicm 1: /* $OpenBSD: cmd-server-info.c,v 1.4 2009/07/26 12:58:44 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:
34: int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
35:
36: const struct cmd_entry cmd_server_info_entry = {
37: "server-info", "info",
38: "",
1.3 nicm 39: 0, 0,
1.1 nicm 40: NULL,
41: NULL,
42: cmd_server_info_exec,
43: NULL,
44: NULL
45: };
46:
47: int
48: cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
49: {
50: struct tty_term *term;
51: struct client *c;
52: struct session *s;
53: struct winlink *wl;
54: struct window *w;
55: struct window_pane *wp;
56: struct tty_code *code;
57: struct tty_term_code_entry *ent;
58: struct utsname un;
59: struct grid *gd;
60: u_int i, j, k;
61: char out[80];
62: char *tim;
63: time_t t;
64: u_int lines, ulines;
65: size_t size, usize;
66:
67: tim = ctime(&start_time);
68: *strchr(tim, '\n') = '\0';
69: ctx->print(ctx, "pid %ld, started %s", (long) getpid(), tim);
70: ctx->print(ctx, "socket path %s, debug level %d%s",
71: socket_path, debug_level, be_quiet ? ", quiet" : "");
72: if (uname(&un) == 0) {
73: ctx->print(ctx, "system is %s %s %s %s",
74: un.sysname, un.release, un.version, un.machine);
75: }
76: if (cfg_file != NULL)
77: ctx->print(ctx, "configuration file is %s", cfg_file);
78: else
79: ctx->print(ctx, "configuration file not specified");
80: ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
81: ctx->print(ctx, "%u clients, %u sessions",
82: ARRAY_LENGTH(&clients), ARRAY_LENGTH(&sessions));
83: ctx->print(ctx, "");
84:
85: ctx->print(ctx, "Clients:");
86: for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
87: c = ARRAY_ITEM(&clients, i);
88: if (c == NULL || c->session == NULL)
89: continue;
90:
91: ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
92: "[flags=0x%x/0x%x]", i, c->tty.path, c->fd, c->tty.fd,
93: c->session->name, c->tty.sx, c->tty.sy, c->tty.termname,
94: c->flags, c->tty.flags);
95: }
96: ctx->print(ctx, "");
97:
98: ctx->print(ctx, "Sessions: [%zu/%zu]",
99: sizeof (struct grid_cell), sizeof (struct grid_utf8));
100: for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
101: s = ARRAY_ITEM(&sessions, i);
102: if (s == NULL)
103: continue;
104:
105: t = s->tv.tv_sec;
106: tim = ctime(&t);
107: *strchr(tim, '\n') = '\0';
108:
109: ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
110: "[flags=0x%x]", i, s->name, winlink_count(&s->windows),
111: tim, s->sx, s->sy, s->flags);
112: RB_FOREACH(wl, winlinks, &s->windows) {
113: w = wl->window;
114: ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
1.5 ! nicm 115: "references=%u, last layout=%d]", wl->idx, w->name,
1.1 nicm 116: w->sx, w->sy, w->flags, w->references,
1.5 ! nicm 117: w->lastlayout);
1.1 nicm 118: j = 0;
119: TAILQ_FOREACH(wp, &w->panes, entry) {
120: lines = ulines = size = usize = 0;
121: gd = wp->base.grid;
122: for (k = 0; k < gd->hsize + gd->sy; k++) {
123: if (gd->data[k] != NULL) {
124: lines++;
125: size += gd->size[k] *
126: sizeof (**gd->data);
127: }
128: if (gd->udata[k] != NULL) {
129: ulines++;
130: usize += gd->usize[k] *
131: sizeof (**gd->udata);
132: }
133: }
134: ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
135: "bytes; UTF-8 %u/%u, %zu bytes", j,
136: wp->tty, (u_long) wp->pid, wp->fd, lines,
137: gd->hsize + gd->sy, size, ulines,
138: gd->hsize + gd->sy, usize);
139: j++;
140: }
141: }
142: }
143: ctx->print(ctx, "");
144:
145: ctx->print(ctx, "Terminals:");
146: SLIST_FOREACH(term, &tty_terms, entry) {
147: ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
148: term->name, term->references, term->flags);
149: for (i = 0; i < NTTYCODE; i++) {
150: ent = &tty_term_codes[i];
151: code = &term->codes[ent->code];
152: switch (code->type) {
153: case TTYCODE_NONE:
154: ctx->print(ctx, "%2u: %s: [missing]",
155: ent->code, ent->name);
156: break;
157: case TTYCODE_STRING:
1.2 nicm 158: strnvis(out, code->value.string, sizeof out,
159: VIS_OCTAL|VIS_TAB|VIS_NL);
1.1 nicm 160: ctx->print(ctx, "%2u: %s: (string) %s",
161: ent->code, ent->name, out);
162: break;
163: case TTYCODE_NUMBER:
164: ctx->print(ctx, "%2u: %s: (number) %d",
165: ent->code, ent->name, code->value.number);
166: break;
167: case TTYCODE_FLAG:
168: ctx->print(ctx, "%2u: %s: (flag) %s",
169: ent->code, ent->name,
170: code->value.flag ? "true" : "false");
171: break;
172: }
173: }
174: }
175: ctx->print(ctx, "");
176:
177: return (0);
178: }