Don't treat TMUX_TMPDIR as a potential file
[tmux-openbsd.git] / cmd-server-info.c
blob6cbabe2b6bd7d1db4f5021411e2184f15605c59f
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
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.
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.
19 #include <sys/types.h>
20 #include <sys/utsname.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <time.h>
25 #include <unistd.h>
26 #include <vis.h>
28 #include "tmux.h"
31 * Show various information about server.
34 enum cmd_retval cmd_server_info_exec(struct cmd *, struct cmd_q *);
36 const struct cmd_entry cmd_server_info_entry = {
37 "server-info", "info",
38 "", 0, 0,
39 "",
41 NULL,
42 cmd_server_info_exec
45 enum cmd_retval
46 cmd_server_info_exec(unused struct cmd *self, struct cmd_q *cmdq)
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;
60 u_int i, j, k, lines;
61 size_t size;
62 char out[80];
63 char *tim;
64 time_t t;
66 tim = ctime(&start_time);
67 *strchr(tim, '\n') = '\0';
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);
71 if (uname(&un) >= 0) {
72 cmdq_print(cmdq, "system is %s %s %s %s",
73 un.sysname, un.release, un.version, un.machine);
75 if (cfg_file != NULL)
76 cmdq_print(cmdq, "configuration file is %s", cfg_file);
77 else
78 cmdq_print(cmdq, "configuration file not specified");
79 cmdq_print(cmdq, "protocol version is %d", PROTOCOL_VERSION);
80 cmdq_print(cmdq, "%s", "");
82 cmdq_print(cmdq, "Clients:");
83 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
84 c = ARRAY_ITEM(&clients, i);
85 if (c == NULL || c->session == NULL)
86 continue;
88 cmdq_print(cmdq,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
89 "class=%u] [flags=0x%x/0x%x, references=%u]", i,
90 c->tty.path, c->ibuf.fd, c->tty.fd, c->session->name,
91 c->tty.sx, c->tty.sy, c->tty.termname,
92 c->tty.tio.c_cc[VERASE], c->tty.class,
93 c->flags, c->tty.flags, c->references);
95 cmdq_print(cmdq, "%s", "");
97 cmdq_print(cmdq, "Sessions: [%zu]", sizeof (struct grid_cell));
98 RB_FOREACH(s, sessions, &sessions) {
99 t = s->creation_time.tv_sec;
100 tim = ctime(&t);
101 *strchr(tim, '\n') = '\0';
103 cmdq_print(cmdq, "%2u: %s: %u windows (created %s) [%ux%u] "
104 "[flags=0x%x]", s->id, s->name,
105 winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
106 RB_FOREACH(wl, winlinks, &s->windows) {
107 w = wl->window;
108 cmdq_print(cmdq, "%4u: %s [%ux%u] [flags=0x%x, "
109 "references=%u, last layout=%d]", wl->idx, w->name,
110 w->sx, w->sy, w->flags, w->references,
111 w->lastlayout);
112 j = 0;
113 TAILQ_FOREACH(wp, &w->panes, entry) {
114 lines = size = 0;
115 gd = wp->base.grid;
116 for (k = 0; k < gd->hsize + gd->sy; k++) {
117 gl = &gd->linedata[k];
118 if (gl->celldata == NULL)
119 continue;
120 lines++;
121 size += gl->cellsize *
122 sizeof *gl->celldata;
124 cmdq_print(cmdq,
125 "%6u: %s %lu %d %u/%u, %zu bytes", j,
126 wp->tty, (u_long) wp->pid, wp->fd, lines,
127 gd->hsize + gd->sy, size);
128 j++;
132 cmdq_print(cmdq, "%s", "");
134 cmdq_print(cmdq, "Terminals:");
135 LIST_FOREACH(term, &tty_terms, entry) {
136 cmdq_print(cmdq, "%s [references=%u, flags=0x%x]:",
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:
143 cmdq_print(cmdq, "%2u: %s: [missing]",
144 ent->code, ent->name);
145 break;
146 case TTYCODE_STRING:
147 strnvis(out, code->value.string, sizeof out,
148 VIS_OCTAL|VIS_TAB|VIS_NL);
149 cmdq_print(cmdq, "%2u: %s: (string) %s",
150 ent->code, ent->name, out);
151 break;
152 case TTYCODE_NUMBER:
153 cmdq_print(cmdq, "%2u: %s: (number) %d",
154 ent->code, ent->name, code->value.number);
155 break;
156 case TTYCODE_FLAG:
157 cmdq_print(cmdq, "%2u: %s: (flag) %s",
158 ent->code, ent->name,
159 code->value.flag ? "true" : "false");
160 break;
164 cmdq_print(cmdq, "%s", "");
166 cmdq_print(cmdq, "Jobs:");
167 LIST_FOREACH(job, &all_jobs, lentry) {
168 cmdq_print(cmdq, "%s [fd=%d, pid=%d, status=%d]",
169 job->cmd, job->fd, job->pid, job->status);
172 return (CMD_RETURN_NORMAL);