Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 184 lines (167 sloc) 5.285 kB
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
1 /* $Id: cmd-server-info.c 2553 2011-07-09 09:42:33Z tcunha $ */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
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",
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
37 "", 0, 0,
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
38 "",
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
39 0,
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
40 NULL,
41 NULL,
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
42 cmd_server_info_exec
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
43 };
44
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
45 /* ARGSUSED */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
46 int
47 cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
48 {
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
49 struct tty_term *term;
50 struct client *c;
51 struct session *s;
52 struct winlink *wl;
53 struct window *w;
54 struct window_pane *wp;
55 struct tty_code *code;
56 const struct tty_term_code_entry *ent;
57 struct utsname un;
58 struct job *job;
59 struct grid *gd;
60 struct grid_line *gl;
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;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
67
68 tim = ctime(&start_time);
69 *strchr(tim, '\n') = '\0';
70 ctx->print(ctx,
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
71 "tmux " VERSION ", pid %ld, started %s", (long) getpid(), tim);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
72 ctx->print(
73 ctx, "socket path %s, debug level %d", socket_path, debug_level);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
74 if (uname(&un) >= 0) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
75 ctx->print(ctx, "system is %s %s %s %s",
76 un.sysname, un.release, un.version, un.machine);
77 }
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", "");
84
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;
90
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
91 ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho] "
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
92 "[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
93 c->ibuf.fd, c->tty.fd, c->session->name,
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
94 c->tty.sx, c->tty.sy, c->tty.termname,
95 c->tty.tio.c_cc[VERASE], c->flags,
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
96 c->tty.flags, c->references);
97 }
98 ctx->print(ctx, "%s", "");
99
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
100 ctx->print(ctx, "Sessions: [%zu/%zu]",
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
101 sizeof (struct grid_cell), sizeof (struct grid_utf8));
77c63de @orebokech Import upstream version 1.4
orebokech authored
102 RB_FOREACH(s, sessions, &sessions) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
103 t = s->creation_time.tv_sec;
104 tim = ctime(&t);
105 *strchr(tim, '\n') = '\0';
106
107 ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
77c63de @orebokech Import upstream version 1.4
orebokech authored
108 "[flags=0x%x]", s->idx, s->name,
109 winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
110 RB_FOREACH(wl, winlinks, &s->windows) {
111 w = wl->window;
112 ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
113 "references=%u, last layout=%d]", wl->idx, w->name,
114 w->sx, w->sy, w->flags, w->references,
115 w->lastlayout);
116 j = 0;
117 TAILQ_FOREACH(wp, &w->panes, entry) {
118 lines = ulines = size = usize = 0;
119 gd = wp->base.grid;
120 for (k = 0; k < gd->hsize + gd->sy; k++) {
121 gl = &gd->linedata[k];
122 if (gl->celldata != NULL) {
123 lines++;
124 size += gl->cellsize *
125 sizeof *gl->celldata;
126 }
127 if (gl->utf8data != NULL) {
128 ulines++;
129 usize += gl->utf8size *
130 sizeof *gl->utf8data;
131 }
132 }
133 ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
134 "bytes; UTF-8 %u/%u, %zu bytes", j,
135 wp->tty, (u_long) wp->pid, wp->fd, lines,
136 gd->hsize + gd->sy, size, ulines,
137 gd->hsize + gd->sy, usize);
138 j++;
139 }
140 }
141 }
142 ctx->print(ctx, "%s", "");
143
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
144 ctx->print(ctx, "Terminals:");
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
145 LIST_FOREACH(term, &tty_terms, entry) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
146 ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
147 term->name, term->references, term->flags);
148 for (i = 0; i < NTTYCODE; i++) {
149 ent = &tty_term_codes[i];
150 code = &term->codes[ent->code];
151 switch (code->type) {
152 case TTYCODE_NONE:
153 ctx->print(ctx, "%2u: %s: [missing]",
154 ent->code, ent->name);
155 break;
156 case TTYCODE_STRING:
157 strnvis(out, code->value.string, sizeof out,
158 VIS_OCTAL|VIS_TAB|VIS_NL);
159 ctx->print(ctx, "%2u: %s: (string) %s",
160 ent->code, ent->name, out);
161 break;
162 case TTYCODE_NUMBER:
163 ctx->print(ctx, "%2u: %s: (number) %d",
164 ent->code, ent->name, code->value.number);
165 break;
166 case TTYCODE_FLAG:
167 ctx->print(ctx, "%2u: %s: (flag) %s",
168 ent->code, ent->name,
169 code->value.flag ? "true" : "false");
170 break;
171 }
172 }
173 }
174 ctx->print(ctx, "%s", "");
175
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
176 ctx->print(ctx, "Jobs:");
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
177 LIST_FOREACH(job, &all_jobs, lentry) {
178 ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d]",
179 job->cmd, job->fd, job->pid, job->status);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
180 }
181
182 return (0);
183 }
Something went wrong with that request. Please try again.