diff --git a/client-fn.c b/client-fn.c index f2cd816b..3171f223 100644 --- a/client-fn.c +++ b/client-fn.c @@ -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 @@ -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); } diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c index 1b1b20d7..c0b887ff 100644 --- a/cmd-list-sessions.c +++ b/cmd-list-sessions.c @@ -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 @@ -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) diff --git a/cmd-server-info.c b/cmd-server-info.c index e5c88f17..b0f505fe 100644 --- a/cmd-server-info.c +++ b/cmd-server-info.c @@ -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 @@ -17,8 +17,10 @@ */ #include +#include #include +#include #include #include #include @@ -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); } diff --git a/server-fn.c b/server-fn.c index c5a042ed..fd158b9f 100644 --- a/server-fn.c +++ b/server-fn.c @@ -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 @@ -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); } diff --git a/session.c b/session.c index ee83f445..9d1e1acf 100644 --- a/session.c +++ b/session.c @@ -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 @@ -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; diff --git a/tmux.c b/tmux.c index 1d92f1af..02016d57 100644 --- a/tmux.c +++ b/tmux.c @@ -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 @@ -356,14 +356,16 @@ main(int argc, char **argv) fatalx("bad MSG_PRINT size"); log_info("%.*s", (int) hdr.size, BUFFER_OUT(cctx.srv_in)); - buffer_remove(cctx.srv_in, hdr.size); + if (hdr.size != 0) + buffer_remove(cctx.srv_in, hdr.size); goto restart; case MSG_ERROR: if (hdr.size > INT_MAX - 1) fatalx("bad MSG_ERROR size"); log_warnx("%.*s", (int) hdr.size, BUFFER_OUT(cctx.srv_in)); - buffer_remove(cctx.srv_in, hdr.size); + if (hdr.size != 0) + buffer_remove(cctx.srv_in, hdr.size); n = 1; goto out; case MSG_READY: diff --git a/tmux.h b/tmux.h index a82c751b..5a5fc37a 100644 --- a/tmux.h +++ b/tmux.h @@ -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 @@ -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 *); diff --git a/window.c b/window.c index 2e33f192..48de0da9 100644 --- a/window.c +++ b/window.c @@ -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 @@ -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) {