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