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