From a4b4b299875d833019cb829ca1bee41d71724f37 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 16 Sep 2015 22:24:54 +0000 Subject: [PATCH 1/5] Rename cmd_q dead flag to a general flags bitmask (will be more flags later). --- cmd-if-shell.c | 2 +- cmd-queue.c | 9 ++++++--- cmd-run-shell.c | 2 +- server-client.c | 2 +- tmux.h | 3 ++- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd-if-shell.c b/cmd-if-shell.c index a307bd2f..0271fdea 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -143,7 +143,7 @@ cmd_if_shell_callback(struct job *job) struct cmd_list *cmdlist; char *cause, *cmd; - if (cmdq->dead) + if (cmdq->flags & CMD_Q_DEAD) return; if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) diff --git a/cmd-queue.c b/cmd-queue.c index af987f59..217045fa 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -35,7 +35,7 @@ cmdq_new(struct client *c) cmdq = xcalloc(1, sizeof *cmdq); cmdq->references = 1; - cmdq->dead = 0; + cmdq->flags = 0; cmdq->client = c; cmdq->client_exit = -1; @@ -51,8 +51,11 @@ cmdq_new(struct client *c) int cmdq_free(struct cmd_q *cmdq) { - if (--cmdq->references != 0) - return (cmdq->dead); + if (--cmdq->references != 0) { + if (cmdq->flags & CMD_Q_DEAD) + return (1); + return (0); + } cmdq_flush(cmdq); free(cmdq); diff --git a/cmd-run-shell.c b/cmd-run-shell.c index 134cbeba..17ac0f76 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -131,7 +131,7 @@ cmd_run_shell_callback(struct job *job) int retcode; u_int lines; - if (cmdq->dead) + if (cmdq->flags & CMD_Q_DEAD) return; cmd = cdata->cmd; diff --git a/server-client.c b/server-client.c index 6669bf05..10768839 100644 --- a/server-client.c +++ b/server-client.c @@ -214,7 +214,7 @@ server_client_lost(struct client *c) free(c->prompt_string); free(c->prompt_buffer); - c->cmdq->dead = 1; + c->cmdq->flags |= CMD_Q_DEAD; cmdq_free(c->cmdq); c->cmdq = NULL; diff --git a/tmux.h b/tmux.h index 6839be84..3fd057e9 100644 --- a/tmux.h +++ b/tmux.h @@ -1305,7 +1305,8 @@ TAILQ_HEAD(cmd_q_items, cmd_q_item); /* Command queue. */ struct cmd_q { int references; - int dead; + int flags; +#define CMD_Q_DEAD 0x1 struct client *client; int client_exit; From d1b73be6e18a9576f4dc3bac73d7e1cc1a135938 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 16 Sep 2015 22:29:30 +0000 Subject: [PATCH 2/5] Hoist some common code out of both branches of an if/else. --- cmd-attach-session.c | 54 +++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/cmd-attach-session.c b/cmd-attach-session.c index a2ae49cb..a7ef1cd9 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -93,6 +93,24 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, session_set_current(s, wl); } + if (cflag != NULL) { + ft = format_create(); + format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, + NULL, NULL); + cp = format_expand(ft, cflag); + format_free(ft); + + fd = open(cp, O_RDONLY|O_DIRECTORY); + free(cp); + if (fd == -1) { + cmdq_error(cmdq, "bad working directory: %s", + strerror(errno)); + return (CMD_RETURN_ERROR); + } + close(s->cwd); + s->cwd = fd; + } + if (c->session != NULL) { if (dflag) { /* @@ -108,24 +126,6 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, } } - if (cflag != NULL) { - ft = format_create(); - format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, - NULL, NULL); - cp = format_expand(ft, cflag); - format_free(ft); - - fd = open(cp, O_RDONLY|O_DIRECTORY); - free(cp); - if (fd == -1) { - cmdq_error(cmdq, "bad working directory: %s", - strerror(errno)); - return (CMD_RETURN_ERROR); - } - close(s->cwd); - s->cwd = fd; - } - if (!Eflag) { update = options_get_string(&s->options, "update-environment"); @@ -146,24 +146,6 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, return (CMD_RETURN_ERROR); } - if (cflag != NULL) { - ft = format_create(); - format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, - NULL, NULL); - cp = format_expand(ft, cflag); - format_free(ft); - - fd = open(cp, O_RDONLY|O_DIRECTORY); - free(cp); - if (fd == -1) { - cmdq_error(cmdq, "bad working directory: %s", - strerror(errno)); - return (CMD_RETURN_ERROR); - } - close(s->cwd); - s->cwd = fd; - } - if (rflag) c->flags |= CLIENT_READONLY; From ecb257f0efad988660b1a3f27bc9e641275cd1f2 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 16 Sep 2015 22:40:05 +0000 Subject: [PATCH 3/5] A few minor style nits. --- cmd-list-panes.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd-list-panes.c b/cmd-list-panes.c index bd34344f..0af391c5 100644 --- a/cmd-list-panes.c +++ b/cmd-list-panes.c @@ -19,7 +19,6 @@ #include #include -#include #include "tmux.h" @@ -30,10 +29,10 @@ enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *); void cmd_list_panes_server(struct cmd *, struct cmd_q *); -void cmd_list_panes_session( - struct cmd *, struct session *, struct cmd_q *, int); -void cmd_list_panes_window(struct cmd *, - struct session *, struct winlink *, struct cmd_q *, int); +void cmd_list_panes_session(struct cmd *, struct session *, struct cmd_q *, + int); +void cmd_list_panes_window(struct cmd *, struct session *, struct winlink *, + struct cmd_q *, int); const struct cmd_entry cmd_list_panes_entry = { "list-panes", "lsp", @@ -77,8 +76,8 @@ cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq) } void -cmd_list_panes_session( - struct cmd *self, struct session *s, struct cmd_q *cmdq, int type) +cmd_list_panes_session(struct cmd *self, struct session *s, struct cmd_q *cmdq, + int type) { struct winlink *wl; @@ -87,8 +86,8 @@ cmd_list_panes_session( } void -cmd_list_panes_window(struct cmd *self, - struct session *s, struct winlink *wl, struct cmd_q *cmdq, int type) +cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl, + struct cmd_q *cmdq, int type) { struct args *args = self->args; struct window_pane *wp; @@ -115,9 +114,9 @@ cmd_list_panes_window(struct cmd *self, "#{?pane_active, (active),}#{?pane_dead, (dead),}"; break; case 2: - template = "#{session_name}:#{window_index}.#{pane_index}: " - "[#{pane_width}x#{pane_height}] [history " - "#{history_size}/#{history_limit}, " + template = "#{session_name}:#{window_index}." + "#{pane_index}: [#{pane_width}x#{pane_height}] " + "[history #{history_size}/#{history_limit}, " "#{history_bytes} bytes] #{pane_id}" "#{?pane_active, (active),}#{?pane_dead, (dead),}"; break; From 232a0ffc34bd1c4c3dbb006369b8c87b9ee55c9a Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 16 Sep 2015 22:40:27 +0000 Subject: [PATCH 4/5] Give some variables less silly names. --- cmd-kill-session.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd-kill-session.c b/cmd-kill-session.c index d7e2a219..74843eb6 100644 --- a/cmd-kill-session.c +++ b/cmd-kill-session.c @@ -41,16 +41,16 @@ enum cmd_retval cmd_kill_session_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; - struct session *s, *s2, *s3; + struct session *s, *sloop, *stmp; if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL) return (CMD_RETURN_ERROR); if (args_has(args, 'a')) { - RB_FOREACH_SAFE(s2, sessions, &sessions, s3) { - if (s != s2) { - server_destroy_session(s2); - session_destroy(s2); + RB_FOREACH_SAFE(sloop, sessions, &sessions, stmp) { + if (sloop != s) { + server_destroy_session(sloop); + session_destroy(sloop); } } } else { From c1d0b6a6eed2fd393ea30d257ce147e8f6b5e6c8 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 16 Sep 2015 22:41:00 +0000 Subject: [PATCH 5/5] Log when cmdq_continue is called. --- cmd-queue.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd-queue.c b/cmd-queue.c index 217045fa..1fe34dce 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -195,6 +195,7 @@ cmdq_continue_one(struct cmd_q *cmdq) int cmdq_continue(struct cmd_q *cmdq) { + struct client *c = cmdq->client; struct cmd_q_item *next; enum cmd_retval retval; int empty; @@ -202,6 +203,9 @@ cmdq_continue(struct cmd_q *cmdq) cmdq->references++; notify_disable(); + log_debug("continuing cmdq %p: flags=%#x, client=%d", cmdq, cmdq->flags, + c != NULL ? c->ibuf.fd : -1); + empty = TAILQ_EMPTY(&cmdq->queue); if (empty) goto empty;