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",
46 cmd_server_info_exec(unused
struct cmd
*self
, struct cmd_q
*cmdq
)
48 struct tty_term
*term
;
53 struct window_pane
*wp
;
54 struct tty_code
*code
;
55 const struct tty_term_code_entry
*ent
;
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
,
71 if (uname(&un
) >= 0) {
72 cmdq_print(cmdq
, "system is %s %s %s %s",
73 un
.sysname
, un
.release
, un
.version
, un
.machine
);
76 cmdq_print(cmdq
, "configuration file is %s", cfg_file
);
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
)
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
;
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
) {
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
,
113 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
116 for (k
= 0; k
< gd
->hsize
+ gd
->sy
; k
++) {
117 gl
= &gd
->linedata
[k
];
118 if (gl
->celldata
== NULL
)
121 size
+= gl
->cellsize
*
122 sizeof *gl
->celldata
;
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
);
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
) {
143 cmdq_print(cmdq
, "%2u: %s: [missing]",
144 ent
->code
, ent
->name
);
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
);
153 cmdq_print(cmdq
, "%2u: %s: (number) %d",
154 ent
->code
, ent
->name
, code
->value
.number
);
157 cmdq_print(cmdq
, "%2u: %s: (flag) %s",
158 ent
->code
, ent
->name
,
159 code
->value
.flag
? "true" : "false");
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
);