[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.31

1.31    ! nicm        1: /* $OpenBSD: cmd-server-info.c,v 1.30 2013/01/18 02:16:21 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.27      nicm       46: enum cmd_retval
1.1       nicm       47: cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
                     48: {
1.20      nicm       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;
1.30      nicm       61:        u_int                                    i, j, k, lines;
                     62:        size_t                                   size;
1.20      nicm       63:        char                                     out[80];
                     64:        char                                    *tim;
                     65:        time_t                                   t;
1.1       nicm       66:
                     67:        tim = ctime(&start_time);
                     68:        *strchr(tim, '\n') = '\0';
                     69:        ctx->print(ctx, "pid %ld, started %s", (long) getpid(), tim);
1.18      nicm       70:        ctx->print(
                     71:            ctx, "socket path %s, debug level %d", socket_path, debug_level);
1.25      matthew    72:        if (uname(&un) >= 0) {
1.12      deraadt    73:                ctx->print(ctx, "system is %s %s %s %s",
1.1       nicm       74:                    un.sysname, un.release, un.version, un.machine);
                     75:        }
                     76:        if (cfg_file != NULL)
                     77:                ctx->print(ctx, "configuration file is %s", cfg_file);
                     78:        else
                     79:                ctx->print(ctx, "configuration file not specified");
                     80:        ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
1.8       nicm       81:        ctx->print(ctx, "%s", "");
1.1       nicm       82:
                     83:        ctx->print(ctx, "Clients:");
                     84:        for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
                     85:                c = ARRAY_ITEM(&clients, i);
                     86:                if (c == NULL || c->session == NULL)
                     87:                        continue;
                     88:
1.26      nicm       89:                ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
1.28      nicm       90:                    "class=%u] [flags=0x%x/0x%x, references=%u]", i,
1.26      nicm       91:                    c->tty.path, c->ibuf.fd, c->tty.fd, c->session->name,
1.22      nicm       92:                    c->tty.sx, c->tty.sy, c->tty.termname,
1.29      nicm       93:                    c->tty.tio.c_cc[VERASE], c->tty.class,
1.26      nicm       94:                    c->flags, c->tty.flags, c->references);
1.1       nicm       95:        }
1.8       nicm       96:        ctx->print(ctx, "%s", "");
1.1       nicm       97:
1.30      nicm       98:        ctx->print(ctx, "Sessions: [%zu]", sizeof (struct grid_cell));
1.19      nicm       99:        RB_FOREACH(s, sessions, &sessions) {
1.14      nicm      100:                t = s->creation_time.tv_sec;
1.1       nicm      101:                tim = ctime(&t);
                    102:                *strchr(tim, '\n') = '\0';
                    103:
                    104:                ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
1.19      nicm      105:                    "[flags=0x%x]", s->idx, s->name,
                    106:                    winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
1.1       nicm      107:                RB_FOREACH(wl, winlinks, &s->windows) {
                    108:                        w = wl->window;
                    109:                        ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
1.5       nicm      110:                            "references=%u, last layout=%d]", wl->idx, w->name,
1.1       nicm      111:                            w->sx, w->sy, w->flags, w->references,
1.5       nicm      112:                            w->lastlayout);
1.1       nicm      113:                        j = 0;
                    114:                        TAILQ_FOREACH(wp, &w->panes, entry) {
1.30      nicm      115:                                lines = size = 0;
1.1       nicm      116:                                gd = wp->base.grid;
                    117:                                for (k = 0; k < gd->hsize + gd->sy; k++) {
1.6       nicm      118:                                        gl = &gd->linedata[k];
1.30      nicm      119:                                        if (gl->celldata == NULL)
                    120:                                                continue;
                    121:                                        lines++;
                    122:                                        size += gl->cellsize *
                    123:                                            sizeof *gl->celldata;
1.1       nicm      124:                                }
1.30      nicm      125:                                ctx->print(ctx,
                    126:                                    "%6u: %s %lu %d %u/%u, %zu bytes", j,
1.1       nicm      127:                                    wp->tty, (u_long) wp->pid, wp->fd, lines,
1.30      nicm      128:                                    gd->hsize + gd->sy, size);
1.1       nicm      129:                                j++;
                    130:                        }
                    131:                }
                    132:        }
1.8       nicm      133:        ctx->print(ctx, "%s", "");
1.1       nicm      134:
1.17      nicm      135:        ctx->print(ctx, "Terminals:");
1.23      nicm      136:        LIST_FOREACH(term, &tty_terms, entry) {
1.1       nicm      137:                ctx->print(ctx, "%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) {
                    143:                        case TTYCODE_NONE:
                    144:                                ctx->print(ctx, "%2u: %s: [missing]",
                    145:                                    ent->code, ent->name);
                    146:                                break;
                    147:                        case TTYCODE_STRING:
1.2       nicm      148:                                strnvis(out, code->value.string, sizeof out,
                    149:                                    VIS_OCTAL|VIS_TAB|VIS_NL);
1.1       nicm      150:                                ctx->print(ctx, "%2u: %s: (string) %s",
                    151:                                    ent->code, ent->name, out);
                    152:                                break;
                    153:                        case TTYCODE_NUMBER:
                    154:                                ctx->print(ctx, "%2u: %s: (number) %d",
                    155:                                    ent->code, ent->name, code->value.number);
                    156:                                break;
                    157:                        case TTYCODE_FLAG:
                    158:                                ctx->print(ctx, "%2u: %s: (flag) %s",
                    159:                                    ent->code, ent->name,
                    160:                                    code->value.flag ? "true" : "false");
                    161:                                break;
                    162:                        }
                    163:                }
                    164:        }
1.8       nicm      165:        ctx->print(ctx, "%s", "");
1.13      nicm      166:
1.17      nicm      167:        ctx->print(ctx, "Jobs:");
1.23      nicm      168:        LIST_FOREACH(job, &all_jobs, lentry) {
1.24      nicm      169:                ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d]",
                    170:                    job->cmd, job->fd, job->pid, job->status);
1.13      nicm      171:        }
1.1       nicm      172:
1.27      nicm      173:        return (CMD_RETURN_NORMAL);
1.1       nicm      174: }