Change server-info format.

This commit is contained in:
Nicholas Marriott 2009-01-10 14:43:43 +00:00
parent a49e9b5b00
commit fd05d07c2b
8 changed files with 83 additions and 41 deletions

View File

@ -1,4 +1,4 @@
/* $Id: client-fn.c,v 1.4 2008-07-01 20:35:16 nicm Exp $ */
/* $Id: client-fn.c,v 1.5 2009-01-10 14:43:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -61,7 +61,7 @@ client_write_server(
hdr.size = len;
buffer_write(cctx->srv_out, &hdr, sizeof hdr);
if (buf != NULL)
if (buf != NULL && len > 0)
buffer_write(cctx->srv_out, buf, len);
}
@ -75,8 +75,8 @@ client_write_server2(struct client_ctx *cctx,
hdr.size = len1 + len2;
buffer_write(cctx->srv_out, &hdr, sizeof hdr);
if (buf1 != NULL)
if (buf1 != NULL && len1 > 0)
buffer_write(cctx->srv_out, buf1, len1);
if (buf2 != NULL)
if (buf2 != NULL && len2 > 0)
buffer_write(cctx->srv_out, buf2, len2);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-sessions.c,v 1.16 2008-08-28 17:45:25 nicm Exp $ */
/* $Id: cmd-list-sessions.c,v 1.17 2009-01-10 14:43:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -45,9 +45,8 @@ void
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
struct session *s;
struct winlink *wl;
char *tim;
u_int i, n;
u_int i;
time_t t;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
@ -55,15 +54,12 @@ cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
if (s == NULL)
continue;
n = 0;
RB_FOREACH(wl, winlinks, &s->windows)
n++;
t = s->tv.tv_sec;
tim = ctime(&t);
*strchr(tim, '\n') = '\0';
ctx->print(ctx, "%s: %u windows"
" (created %s) [%ux%u]", s->name, n, tim, s->sx, s->sy);
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]",
s->name, winlink_count(&s->windows), tim, s->sx, s->sy);
}
if (ctx->cmdclient != NULL)

View File

@ -1,4 +1,4 @@
/* $Id: cmd-server-info.c,v 1.5 2009-01-10 12:52:57 nicm Exp $ */
/* $Id: cmd-server-info.c,v 1.6 2009-01-10 14:43:43 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -17,8 +17,10 @@
*/
#include <sys/types.h>
#include <sys/utsname.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <vis.h>
@ -48,33 +50,60 @@ void
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
struct tty_term *term;
struct client *cmdclient;
struct client *c;
struct session *s;
struct tty_code *code;
struct tty_term_code_entry *ent;
struct utsname un;
u_int i;
char s[BUFSIZ];
char out[BUFSIZ];
char *tim;
time_t t;
ctx->print(ctx, "tmux " BUILD
", pid %ld, started %s", (long) getpid(), ctime(&start_time));
tim = ctime(&start_time);
*strchr(tim, '\n') = '\0';
ctx->print(ctx,
"tmux " BUILD ", pid %ld, started %s", (long) getpid(), tim);
ctx->print(ctx, "socket path %s, debug level %d%s",
socket_path, debug_level, be_quiet ? ", quiet" : "");
if (uname(&un) == 0) {
ctx->print(ctx, "system is %s %s %s %s",
un.sysname, un.release, un.version, un.machine);
}
if (cfg_file != NULL)
ctx->print(ctx, "configuration file %s", cfg_file);
ctx->print(ctx, "configuration file is %s", cfg_file);
else
ctx->print(ctx, "configuration file not specified");
ctx->print(ctx, "%u clients, %u sessions",
ARRAY_LENGTH(&clients), ARRAY_LENGTH(&sessions));
ctx->print(ctx, "");
cmdclient = ctx->cmdclient;
ctx->cmdclient = NULL;
ctx->print(ctx, "Clients:");
cmd_list_clients_entry.exec(self, ctx);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
ctx->print(ctx, " %2d: %s (%d, %d): %s [%ux%u %s] "
"[flags=0x%x]", i, c->tty.path, c->fd, c->tty.fd,
c->session->name, c->sx, c->sy, c->tty.termname, c->flags);
}
ctx->print(ctx, "");
ctx->print(ctx, "Sessions:");
cmd_list_sessions_entry.exec(self, ctx);
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
s = ARRAY_ITEM(&sessions, i);
if (s == NULL)
continue;
t = s->tv.tv_sec;
tim = ctime(&t);
*strchr(tim, '\n') = '\0';
ctx->print(ctx, " %2d: %s: %u windows (created %s) [%ux%u] "
"[flags=0x%x]", i, s->name, winlink_count(&s->windows),
tim, s->sx, s->sy, s->flags);
}
ctx->print(ctx, "");
ctx->print(ctx, "Terminals:");
@ -86,23 +115,23 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
code = &term->codes[ent->code];
switch (code->type) {
case TTYCODE_NONE:
ctx->print(ctx, " %2d,%s: [missing]",
ctx->print(ctx, " %2d: %s: [missing]",
ent->code, ent->name);
break;
case TTYCODE_STRING:
strnvis(s, code->value.string,
sizeof s, VIS_OCTAL|VIS_WHITE);
s[(sizeof s) - 1] = '\0';
strnvis(out, code->value.string,
sizeof out, VIS_OCTAL|VIS_WHITE);
out[(sizeof out) - 1] = '\0';
ctx->print(ctx, " %2d,%s: (string) %s",
ent->code, ent->name, s);
ctx->print(ctx, " %2d: %s: (string) %s",
ent->code, ent->name, out);
break;
case TTYCODE_NUMBER:
ctx->print(ctx, " %2d,%s: (number) %d",
ctx->print(ctx, " %2d: %s: (number) %d",
ent->code, ent->name, code->value.number);
break;
case TTYCODE_FLAG:
ctx->print(ctx, " %2d,%s: (flag) %s",
ctx->print(ctx, " %2d: %s: (flag) %s",
ent->code, ent->name,
code->value.flag ? "true" : "false");
break;
@ -111,6 +140,6 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
}
ctx->print(ctx, "");
if (cmdclient != NULL)
server_write_client(cmdclient, MSG_EXIT, NULL, 0);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
}

View File

@ -1,4 +1,4 @@
/* $Id: server-fn.c,v 1.51 2009-01-06 15:37:15 nicm Exp $ */
/* $Id: server-fn.c,v 1.52 2009-01-10 14:43:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -102,7 +102,7 @@ server_write_client(
hdr.size = len;
buffer_write(c->out, &hdr, sizeof hdr);
if (buf != NULL)
if (buf != NULL && len > 0)
buffer_write(c->out, buf, len);
}

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.47 2008-12-08 16:19:51 nicm Exp $ */
/* $Id: session.c,v 1.48 2009-01-10 14:43:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -115,6 +115,7 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
u_int i;
s = xmalloc(sizeof *s);
s->flags = 0;
if (gettimeofday(&s->tv, NULL) != 0)
fatal("gettimeofday");
s->curw = NULL;

4
tmux.c
View File

@ -1,4 +1,4 @@
/* $Id: tmux.c,v 1.88 2009-01-10 01:51:22 nicm Exp $ */
/* $Id: tmux.c,v 1.89 2009-01-10 14:43:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -356,6 +356,7 @@ main(int argc, char **argv)
fatalx("bad MSG_PRINT size");
log_info("%.*s",
(int) hdr.size, BUFFER_OUT(cctx.srv_in));
if (hdr.size != 0)
buffer_remove(cctx.srv_in, hdr.size);
goto restart;
case MSG_ERROR:
@ -363,6 +364,7 @@ main(int argc, char **argv)
fatalx("bad MSG_ERROR size");
log_warnx("%.*s",
(int) hdr.size, BUFFER_OUT(cctx.srv_in));
if (hdr.size != 0)
buffer_remove(cctx.srv_in, hdr.size);
n = 1;
goto out;

3
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.214 2009-01-10 01:51:22 nicm Exp $ */
/* $Id: tmux.h,v 1.215 2009-01-10 14:43:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -1331,6 +1331,7 @@ RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
struct winlink *winlink_find_by_index(struct winlinks *, int);
struct winlink *winlink_find_by_window(struct winlinks *, struct window *);
int winlink_next_index(struct winlinks *);
u_int winlink_count(struct winlinks *);
struct winlink *winlink_add(struct winlinks *, struct window *, int);
void winlink_remove(struct winlinks *, struct winlink *);
struct winlink *winlink_next(struct winlinks *, struct winlink *);

View File

@ -1,4 +1,4 @@
/* $Id: window.c,v 1.52 2008-12-08 16:19:51 nicm Exp $ */
/* $Id: window.c,v 1.53 2009-01-10 14:43:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -99,6 +99,19 @@ winlink_next_index(struct winlinks *wwl)
fatalx("no free indexes");
}
u_int
winlink_count(struct winlinks *wwl)
{
struct winlink *wl;
u_int n;
n = 0;
RB_FOREACH(wl, winlinks, wwl)
n++;
return (n);
}
struct winlink *
winlink_add(struct winlinks *wwl, struct window *w, int idx)
{