Annotation of src/usr.bin/tmux/cmd-server-info.c, Revision 1.15
1.15 ! nicm 1: /* $OpenBSD: cmd-server-info.c,v 1.14 2009/11/03 20:29:47 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.15 ! nicm 39: 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;
1.13 nicm 59: struct job *job;
1.1 nicm 60: struct grid *gd;
1.6 nicm 61: struct grid_line *gl;
1.1 nicm 62: u_int i, j, k;
63: char out[80];
64: char *tim;
65: time_t t;
66: u_int lines, ulines;
67: size_t size, usize;
68:
69: tim = ctime(&start_time);
70: *strchr(tim, '\n') = '\0';
71: ctx->print(ctx, "pid %ld, started %s", (long) getpid(), tim);
1.11 nicm 72: ctx->print(ctx, "socket path %s, debug level %d%s",
73: socket_path, debug_level, be_quiet ? ", quiet" : "");
1.12 deraadt 74: if (uname(&un) == 0) {
75: ctx->print(ctx, "system is %s %s %s %s",
1.1 nicm 76: un.sysname, un.release, un.version, un.machine);
77: }
78: if (cfg_file != NULL)
79: ctx->print(ctx, "configuration file is %s", cfg_file);
80: else
81: ctx->print(ctx, "configuration file not specified");
82: ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
83: ctx->print(ctx, "%u clients, %u sessions",
84: ARRAY_LENGTH(&clients), ARRAY_LENGTH(&sessions));
1.8 nicm 85: ctx->print(ctx, "%s", "");
1.1 nicm 86:
87: ctx->print(ctx, "Clients:");
88: for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
89: c = ARRAY_ITEM(&clients, i);
90: if (c == NULL || c->session == NULL)
91: continue;
92:
93: ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
1.10 nicm 94: "[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
95: c->ibuf.fd, c->tty.fd, c->session->name,
96: c->tty.sx, c->tty.sy, c->tty.termname, c->flags,
97: c->tty.flags, c->references);
1.1 nicm 98: }
1.8 nicm 99: ctx->print(ctx, "%s", "");
1.1 nicm 100:
101: ctx->print(ctx, "Sessions: [%zu/%zu]",
102: sizeof (struct grid_cell), sizeof (struct grid_utf8));
103: for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
104: s = ARRAY_ITEM(&sessions, i);
105: if (s == NULL)
106: continue;
107:
1.14 nicm 108: t = s->creation_time.tv_sec;
1.1 nicm 109: tim = ctime(&t);
110: *strchr(tim, '\n') = '\0';
111:
112: ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
1.10 nicm 113: "[flags=0x%x, references=%u]", i, s->name,
114: winlink_count(&s->windows), tim, s->sx, s->sy, s->flags,
115: s->references);
1.1 nicm 116: RB_FOREACH(wl, winlinks, &s->windows) {
117: w = wl->window;
118: ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
1.5 nicm 119: "references=%u, last layout=%d]", wl->idx, w->name,
1.1 nicm 120: w->sx, w->sy, w->flags, w->references,
1.5 nicm 121: w->lastlayout);
1.1 nicm 122: j = 0;
123: TAILQ_FOREACH(wp, &w->panes, entry) {
124: lines = ulines = size = usize = 0;
125: gd = wp->base.grid;
126: for (k = 0; k < gd->hsize + gd->sy; k++) {
1.6 nicm 127: gl = &gd->linedata[k];
128: if (gl->celldata != NULL) {
1.1 nicm 129: lines++;
1.6 nicm 130: size += gl->cellsize *
131: sizeof *gl->celldata;
1.1 nicm 132: }
1.6 nicm 133: if (gl->utf8data != NULL) {
1.1 nicm 134: ulines++;
1.6 nicm 135: usize += gl->utf8size *
136: sizeof *gl->utf8data;
1.1 nicm 137: }
138: }
139: ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
140: "bytes; UTF-8 %u/%u, %zu bytes", j,
141: wp->tty, (u_long) wp->pid, wp->fd, lines,
142: gd->hsize + gd->sy, size, ulines,
143: gd->hsize + gd->sy, usize);
144: j++;
145: }
146: }
147: }
1.8 nicm 148: ctx->print(ctx, "%s", "");
1.1 nicm 149:
150: ctx->print(ctx, "Terminals:");
151: SLIST_FOREACH(term, &tty_terms, entry) {
152: ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
153: term->name, term->references, term->flags);
154: for (i = 0; i < NTTYCODE; i++) {
155: ent = &tty_term_codes[i];
156: code = &term->codes[ent->code];
157: switch (code->type) {
158: case TTYCODE_NONE:
159: ctx->print(ctx, "%2u: %s: [missing]",
160: ent->code, ent->name);
161: break;
162: case TTYCODE_STRING:
1.2 nicm 163: strnvis(out, code->value.string, sizeof out,
164: VIS_OCTAL|VIS_TAB|VIS_NL);
1.1 nicm 165: ctx->print(ctx, "%2u: %s: (string) %s",
166: ent->code, ent->name, out);
167: break;
168: case TTYCODE_NUMBER:
169: ctx->print(ctx, "%2u: %s: (number) %d",
170: ent->code, ent->name, code->value.number);
171: break;
172: case TTYCODE_FLAG:
173: ctx->print(ctx, "%2u: %s: (flag) %s",
174: ent->code, ent->name,
175: code->value.flag ? "true" : "false");
176: break;
177: }
178: }
179: }
1.8 nicm 180: ctx->print(ctx, "%s", "");
1.13 nicm 181:
182: ctx->print(ctx, "Jobs:");
183: SLIST_FOREACH(job, &all_jobs, lentry) {
184: ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d, flags=0x%x]",
185: job->cmd, job->fd, job->pid, job->status, job->flags);
186: }
1.1 nicm 187:
188: return (0);
189: }