Use TMPDIR if set, from Han Boetes.
[tmux-openbsd.git] / cmd-server-info.c
blob4bd651433bf966fd1a1efe39e794aa390072b073
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 "", 0, 0,
39 "",
41 NULL,
42 NULL,
43 cmd_server_info_exec
46 /* ARGSUSED */
47 int
48 cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
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;
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;
69 tim = ctime(&start_time);
70 *strchr(tim, '\n') = '\0';
71 ctx->print(ctx, "pid %ld, started %s", (long) getpid(), tim);
72 ctx->print(
73 ctx, "socket path %s, debug level %d", socket_path, debug_level);
74 if (uname(&un) == 0) {
75 ctx->print(ctx, "system is %s %s %s %s",
76 un.sysname, un.release, un.version, un.machine);
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, "%s", "");
85 ctx->print(ctx, "Clients:");
86 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
87 c = ARRAY_ITEM(&clients, i);
88 if (c == NULL || c->session == NULL)
89 continue;
91 ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
92 "[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
93 c->ibuf.fd, c->tty.fd, c->session->name,
94 c->tty.sx, c->tty.sy, c->tty.termname, c->flags,
95 c->tty.flags, c->references);
97 ctx->print(ctx, "%s", "");
99 ctx->print(ctx, "Sessions: [%zu/%zu]",
100 sizeof (struct grid_cell), sizeof (struct grid_utf8));
101 RB_FOREACH(s, sessions, &sessions) {
102 t = s->creation_time.tv_sec;
103 tim = ctime(&t);
104 *strchr(tim, '\n') = '\0';
106 ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
107 "[flags=0x%x]", s->idx, s->name,
108 winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
109 RB_FOREACH(wl, winlinks, &s->windows) {
110 w = wl->window;
111 ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
112 "references=%u, last layout=%d]", wl->idx, w->name,
113 w->sx, w->sy, w->flags, w->references,
114 w->lastlayout);
115 j = 0;
116 TAILQ_FOREACH(wp, &w->panes, entry) {
117 lines = ulines = size = usize = 0;
118 gd = wp->base.grid;
119 for (k = 0; k < gd->hsize + gd->sy; k++) {
120 gl = &gd->linedata[k];
121 if (gl->celldata != NULL) {
122 lines++;
123 size += gl->cellsize *
124 sizeof *gl->celldata;
126 if (gl->utf8data != NULL) {
127 ulines++;
128 usize += gl->utf8size *
129 sizeof *gl->utf8data;
132 ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
133 "bytes; UTF-8 %u/%u, %zu bytes", j,
134 wp->tty, (u_long) wp->pid, wp->fd, lines,
135 gd->hsize + gd->sy, size, ulines,
136 gd->hsize + gd->sy, usize);
137 j++;
141 ctx->print(ctx, "%s", "");
143 ctx->print(ctx, "Terminals:");
144 SLIST_FOREACH(term, &tty_terms, entry) {
145 ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
146 term->name, term->references, term->flags);
147 for (i = 0; i < NTTYCODE; i++) {
148 ent = &tty_term_codes[i];
149 code = &term->codes[ent->code];
150 switch (code->type) {
151 case TTYCODE_NONE:
152 ctx->print(ctx, "%2u: %s: [missing]",
153 ent->code, ent->name);
154 break;
155 case TTYCODE_STRING:
156 strnvis(out, code->value.string, sizeof out,
157 VIS_OCTAL|VIS_TAB|VIS_NL);
158 ctx->print(ctx, "%2u: %s: (string) %s",
159 ent->code, ent->name, out);
160 break;
161 case TTYCODE_NUMBER:
162 ctx->print(ctx, "%2u: %s: (number) %d",
163 ent->code, ent->name, code->value.number);
164 break;
165 case TTYCODE_FLAG:
166 ctx->print(ctx, "%2u: %s: (flag) %s",
167 ent->code, ent->name,
168 code->value.flag ? "true" : "false");
169 break;
173 ctx->print(ctx, "%s", "");
175 ctx->print(ctx, "Jobs:");
176 SLIST_FOREACH(job, &all_jobs, lentry) {
177 ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d, flags=0x%x]",
178 job->cmd, job->fd, job->pid, job->status, job->flags);
181 return (0);