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>
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",
47 cmd_server_info_exec(unused
struct cmd
*self
, struct cmd_q
*cmdq
)
49 struct tty_term
*term
;
54 struct window_pane
*wp
;
55 struct tty_code
*code
;
56 const struct tty_term_code_entry
*ent
;
67 tim
= ctime(&start_time
);
68 *strchr(tim
, '\n') = '\0';
69 cmdq_print(cmdq
, "pid %ld, started %s", (long) getpid(), tim
);
70 cmdq_print(cmdq
, "socket path %s, debug level %d", socket_path
,
72 if (uname(&un
) >= 0) {
73 cmdq_print(cmdq
, "system is %s %s %s %s",
74 un
.sysname
, un
.release
, un
.version
, un
.machine
);
77 cmdq_print(cmdq
, "configuration file is %s", cfg_file
);
79 cmdq_print(cmdq
, "configuration file not specified");
80 cmdq_print(cmdq
, "protocol version is %d", PROTOCOL_VERSION
);
81 cmdq_print(cmdq
, "%s", "");
83 cmdq_print(cmdq
, "Clients:");
84 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
85 c
= ARRAY_ITEM(&clients
, i
);
86 if (c
== NULL
|| c
->session
== NULL
)
89 cmdq_print(cmdq
,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
90 "class=%u] [flags=0x%x/0x%x, references=%u]", i
,
91 c
->tty
.path
, c
->ibuf
.fd
, c
->tty
.fd
, c
->session
->name
,
92 c
->tty
.sx
, c
->tty
.sy
, c
->tty
.termname
,
93 c
->tty
.tio
.c_cc
[VERASE
], c
->tty
.class,
94 c
->flags
, c
->tty
.flags
, c
->references
);
96 cmdq_print(cmdq
, "%s", "");
98 cmdq_print(cmdq
, "Sessions: [%zu]", sizeof (struct grid_cell
));
99 RB_FOREACH(s
, sessions
, &sessions
) {
100 t
= s
->creation_time
.tv_sec
;
102 *strchr(tim
, '\n') = '\0';
104 cmdq_print(cmdq
, "%2u: %s: %u windows (created %s) [%ux%u] "
105 "[flags=0x%x]", s
->id
, s
->name
,
106 winlink_count(&s
->windows
), tim
, s
->sx
, s
->sy
, s
->flags
);
107 RB_FOREACH(wl
, winlinks
, &s
->windows
) {
109 cmdq_print(cmdq
, "%4u: %s [%ux%u] [flags=0x%x, "
110 "references=%u, last layout=%d]", wl
->idx
, w
->name
,
111 w
->sx
, w
->sy
, w
->flags
, w
->references
,
114 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
117 for (k
= 0; k
< gd
->hsize
+ gd
->sy
; k
++) {
118 gl
= &gd
->linedata
[k
];
119 if (gl
->celldata
== NULL
)
122 size
+= gl
->cellsize
*
123 sizeof *gl
->celldata
;
126 "%6u: %s %lu %d %u/%u, %zu bytes", j
,
127 wp
->tty
, (u_long
) wp
->pid
, wp
->fd
, lines
,
128 gd
->hsize
+ gd
->sy
, size
);
133 cmdq_print(cmdq
, "%s", "");
135 cmdq_print(cmdq
, "Terminals:");
136 LIST_FOREACH(term
, &tty_terms
, entry
) {
137 cmdq_print(cmdq
, "%s [references=%u, flags=0x%x]:",
138 term
->name
, term
->references
, term
->flags
);
139 for (i
= 0; i
< NTTYCODE
; i
++) {
140 ent
= &tty_term_codes
[i
];
141 code
= &term
->codes
[ent
->code
];
142 switch (code
->type
) {
144 cmdq_print(cmdq
, "%2u: %s: [missing]",
145 ent
->code
, ent
->name
);
148 strnvis(out
, code
->value
.string
, sizeof out
,
149 VIS_OCTAL
|VIS_TAB
|VIS_NL
);
150 cmdq_print(cmdq
, "%2u: %s: (string) %s",
151 ent
->code
, ent
->name
, out
);
154 cmdq_print(cmdq
, "%2u: %s: (number) %d",
155 ent
->code
, ent
->name
, code
->value
.number
);
158 cmdq_print(cmdq
, "%2u: %s: (flag) %s",
159 ent
->code
, ent
->name
,
160 code
->value
.flag
? "true" : "false");
165 cmdq_print(cmdq
, "%s", "");
167 cmdq_print(cmdq
, "Jobs:");
168 LIST_FOREACH(job
, &all_jobs
, lentry
) {
169 cmdq_print(cmdq
, "%s [fd=%d, pid=%d, status=%d]",
170 job
->cmd
, job
->fd
, job
->pid
, job
->status
);
173 return (CMD_RETURN_NORMAL
);