[BACK]Return to cmd-server-info.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-server-info.c, Revision 1.27

1.27    ! nicm        1: /* $OpenBSD: cmd-server-info.c,v 1.26 2012/03/15 10:36:00 nicm Exp $ */
1.1       nicm        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>
1.2       nicm       26: #include <vis.h>
1.1       nicm       27:
                     28: #include "tmux.h"
                     29:
                     30: /*
                     31:  * Show various information about server.
                     32:  */
                     33:
1.27    ! nicm       34: enum cmd_retval         cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
1.1       nicm       35:
                     36: const struct cmd_entry cmd_server_info_entry = {
                     37:        "server-info", "info",
1.21      nicm       38:        "", 0, 0,
1.1       nicm       39:        "",
1.21      nicm       40:        0,
1.1       nicm       41:        NULL,
                     42:        NULL,
1.21      nicm       43:        cmd_server_info_exec
1.1       nicm       44: };
                     45:
1.16      nicm       46: /* ARGSUSED */
1.27    ! nicm       47: enum cmd_retval
1.1       nicm       48: cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
                     49: {
1.20      nicm       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;
1.1       nicm       68:
                     69:        tim = ctime(&start_time);
                     70:        *strchr(tim, '\n') = '\0';
                     71:        ctx->print(ctx, "pid %ld, started %s", (long) getpid(), tim);
1.18      nicm       72:        ctx->print(
                     73:            ctx, "socket path %s, debug level %d", socket_path, debug_level);
1.25      matthew    74:        if (uname(&un) >= 0) {
1.12      deraadt    75:                ctx->print(ctx, "system is %s %s %s %s",
1.1       nicm       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);
1.8       nicm       83:        ctx->print(ctx, "%s", "");
1.1       nicm       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:
1.26      nicm       91:                ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
                     92:                    "xterm=%u] [flags=0x%x/0x%x, references=%u]", i,
                     93:                    c->tty.path, c->ibuf.fd, c->tty.fd, c->session->name,
1.22      nicm       94:                    c->tty.sx, c->tty.sy, c->tty.termname,
1.26      nicm       95:                    c->tty.tio.c_cc[VERASE], c->tty.xterm_version,
                     96:                    c->flags, c->tty.flags, c->references);
1.1       nicm       97:        }
1.8       nicm       98:        ctx->print(ctx, "%s", "");
1.1       nicm       99:
1.17      nicm      100:        ctx->print(ctx, "Sessions: [%zu/%zu]",
1.1       nicm      101:            sizeof (struct grid_cell), sizeof (struct grid_utf8));
1.19      nicm      102:        RB_FOREACH(s, sessions, &sessions) {
1.14      nicm      103:                t = s->creation_time.tv_sec;
1.1       nicm      104:                tim = ctime(&t);
                    105:                *strchr(tim, '\n') = '\0';
                    106:
                    107:                ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
1.19      nicm      108:                    "[flags=0x%x]", s->idx, s->name,
                    109:                    winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
1.1       nicm      110:                RB_FOREACH(wl, winlinks, &s->windows) {
                    111:                        w = wl->window;
                    112:                        ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
1.5       nicm      113:                            "references=%u, last layout=%d]", wl->idx, w->name,
1.1       nicm      114:                            w->sx, w->sy, w->flags, w->references,
1.5       nicm      115:                            w->lastlayout);
1.1       nicm      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++) {
1.6       nicm      121:                                        gl = &gd->linedata[k];
                    122:                                        if (gl->celldata != NULL) {
1.1       nicm      123:                                                lines++;
1.6       nicm      124:                                                size += gl->cellsize *
                    125:                                                    sizeof *gl->celldata;
1.1       nicm      126:                                        }
1.6       nicm      127:                                        if (gl->utf8data != NULL) {
1.1       nicm      128:                                                ulines++;
1.6       nicm      129:                                                usize += gl->utf8size *
                    130:                                                    sizeof *gl->utf8data;
1.1       nicm      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:        }
1.8       nicm      142:        ctx->print(ctx, "%s", "");
1.1       nicm      143:
1.17      nicm      144:        ctx->print(ctx, "Terminals:");
1.23      nicm      145:        LIST_FOREACH(term, &tty_terms, entry) {
1.1       nicm      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:
1.2       nicm      157:                                strnvis(out, code->value.string, sizeof out,
                    158:                                    VIS_OCTAL|VIS_TAB|VIS_NL);
1.1       nicm      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:        }
1.8       nicm      174:        ctx->print(ctx, "%s", "");
1.13      nicm      175:
1.17      nicm      176:        ctx->print(ctx, "Jobs:");
1.23      nicm      177:        LIST_FOREACH(job, &all_jobs, lentry) {
1.24      nicm      178:                ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d]",
                    179:                    job->cmd, job->fd, job->pid, job->status);
1.13      nicm      180:        }
1.1       nicm      181:
1.27    ! nicm      182:        return (CMD_RETURN_NORMAL);
1.1       nicm      183: }