Don't return if in the current window since we may want to report a bell
[tmux-openbsd.git] / cmd-server-info.c
blob60acbdf8741623e75e20e057325b0064efaefff3
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 int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
36 const struct cmd_entry cmd_server_info_entry = {
37 "server-info", "info",
38 "",
39 0, "",
40 NULL,
41 NULL,
42 cmd_server_info_exec,
43 NULL,
44 NULL
47 /* ARGSUSED */
48 int
49 cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
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 job *job;
61 struct grid *gd;
62 struct grid_line *gl;
63 u_int i, j, k;
64 char out[80];
65 char *tim;
66 time_t t;
67 u_int lines, ulines;
68 size_t size, usize;
70 tim = ctime(&start_time);
71 *strchr(tim, '\n') = '\0';
72 ctx->print(ctx, "pid %ld, started %s", (long) getpid(), tim);
73 ctx->print(
74 ctx, "socket path %s, debug level %d", socket_path, debug_level);
75 if (uname(&un) == 0) {
76 ctx->print(ctx, "system is %s %s %s %s",
77 un.sysname, un.release, un.version, un.machine);
79 if (cfg_file != NULL)
80 ctx->print(ctx, "configuration file is %s", cfg_file);
81 else
82 ctx->print(ctx, "configuration file not specified");
83 ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
84 ctx->print(ctx, "%u clients, %u sessions",
85 ARRAY_LENGTH(&clients), ARRAY_LENGTH(&sessions));
86 ctx->print(ctx, "%s", "");
88 ctx->print(ctx, "Clients:");
89 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
90 c = ARRAY_ITEM(&clients, i);
91 if (c == NULL || c->session == NULL)
92 continue;
94 ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
95 "[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
96 c->ibuf.fd, c->tty.fd, c->session->name,
97 c->tty.sx, c->tty.sy, c->tty.termname, c->flags,
98 c->tty.flags, c->references);
100 ctx->print(ctx, "%s", "");
102 ctx->print(ctx, "Sessions: [%zu/%zu]",
103 sizeof (struct grid_cell), sizeof (struct grid_utf8));
104 for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
105 s = ARRAY_ITEM(&sessions, i);
106 if (s == NULL)
107 continue;
109 t = s->creation_time.tv_sec;
110 tim = ctime(&t);
111 *strchr(tim, '\n') = '\0';
113 ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
114 "[flags=0x%x, references=%u]", i, s->name,
115 winlink_count(&s->windows), tim, s->sx, s->sy, s->flags,
116 s->references);
117 RB_FOREACH(wl, winlinks, &s->windows) {
118 w = wl->window;
119 ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
120 "references=%u, last layout=%d]", wl->idx, w->name,
121 w->sx, w->sy, w->flags, w->references,
122 w->lastlayout);
123 j = 0;
124 TAILQ_FOREACH(wp, &w->panes, entry) {
125 lines = ulines = size = usize = 0;
126 gd = wp->base.grid;
127 for (k = 0; k < gd->hsize + gd->sy; k++) {
128 gl = &gd->linedata[k];
129 if (gl->celldata != NULL) {
130 lines++;
131 size += gl->cellsize *
132 sizeof *gl->celldata;
134 if (gl->utf8data != NULL) {
135 ulines++;
136 usize += gl->utf8size *
137 sizeof *gl->utf8data;
140 ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
141 "bytes; UTF-8 %u/%u, %zu bytes", j,
142 wp->tty, (u_long) wp->pid, wp->fd, lines,
143 gd->hsize + gd->sy, size, ulines,
144 gd->hsize + gd->sy, usize);
145 j++;
149 ctx->print(ctx, "%s", "");
151 ctx->print(ctx, "Terminals:");
152 SLIST_FOREACH(term, &tty_terms, entry) {
153 ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
154 term->name, term->references, term->flags);
155 for (i = 0; i < NTTYCODE; i++) {
156 ent = &tty_term_codes[i];
157 code = &term->codes[ent->code];
158 switch (code->type) {
159 case TTYCODE_NONE:
160 ctx->print(ctx, "%2u: %s: [missing]",
161 ent->code, ent->name);
162 break;
163 case TTYCODE_STRING:
164 strnvis(out, code->value.string, sizeof out,
165 VIS_OCTAL|VIS_TAB|VIS_NL);
166 ctx->print(ctx, "%2u: %s: (string) %s",
167 ent->code, ent->name, out);
168 break;
169 case TTYCODE_NUMBER:
170 ctx->print(ctx, "%2u: %s: (number) %d",
171 ent->code, ent->name, code->value.number);
172 break;
173 case TTYCODE_FLAG:
174 ctx->print(ctx, "%2u: %s: (flag) %s",
175 ent->code, ent->name,
176 code->value.flag ? "true" : "false");
177 break;
181 ctx->print(ctx, "%s", "");
183 ctx->print(ctx, "Jobs:");
184 SLIST_FOREACH(job, &all_jobs, lentry) {
185 ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d, flags=0x%x]",
186 job->cmd, job->fd, job->pid, job->status, job->flags);
189 return (0);