From 4c9f41f1adbdf2e9c5fa2def959ac13ea4a9785c Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 10 Oct 2013 11:45:28 +0000 Subject: Pass flags into cmdq_guard as an argument since sometimes cmdq->cmd can be NULL. Avoids crash when a command in a command client can't be parsed. --- cmd-queue.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'cmd-queue.c') diff --git a/cmd-queue.c b/cmd-queue.c index 904b092c..f3506a34 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -154,18 +154,15 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...) /* Print a guard line. */ int -cmdq_guard(struct cmd_q *cmdq, const char *guard) +cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags) { struct client *c = cmdq->client; - int flags; if (c == NULL) return 0; if (!(c->flags & CLIENT_CONTROL)) return 0; - flags = !!(cmdq->cmd->flags & CMD_CONTROL); - evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard, (long) cmdq->time, cmdq->number, flags); server_push_stdout(c); @@ -202,7 +199,7 @@ cmdq_continue(struct cmd_q *cmdq) { struct cmd_q_item *next; enum cmd_retval retval; - int empty, guard; + int empty, guard, flags; char s[1024]; notify_disable(); @@ -228,13 +225,16 @@ cmdq_continue(struct cmd_q *cmdq) cmdq->time = time(NULL); cmdq->number++; - guard = cmdq_guard(cmdq, "begin"); + flags = !!(cmdq->cmd->flags & CMD_CONTROL); + guard = cmdq_guard(cmdq, "begin", flags); + retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq); + if (guard) { if (retval == CMD_RETURN_ERROR) - cmdq_guard(cmdq, "error"); + cmdq_guard(cmdq, "error", flags); else - cmdq_guard(cmdq, "end"); + cmdq_guard(cmdq, "end", flags); } if (retval == CMD_RETURN_ERROR) -- cgit From b822d24b15669a0b7d325e2a2f04959b05a3d4fb Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 10 Oct 2013 12:07:36 +0000 Subject: Support -c for new-session, based on code from J Raynor. --- cmd-queue.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'cmd-queue.c') diff --git a/cmd-queue.c b/cmd-queue.c index f3506a34..1eacb4bc 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -35,7 +35,7 @@ cmdq_new(struct client *c) cmdq->dead = 0; cmdq->client = c; - cmdq->client_exit = 0; + cmdq->client_exit = -1; TAILQ_INIT(&cmdq->queue); cmdq->item = NULL; @@ -259,7 +259,7 @@ cmdq_continue(struct cmd_q *cmdq) } while (cmdq->item != NULL); empty: - if (cmdq->client_exit) + if (cmdq->client_exit > 0) cmdq->client->flags |= CLIENT_EXIT; if (cmdq->emptyfn != NULL) cmdq->emptyfn(cmdq); /* may free cmdq */ @@ -283,3 +283,27 @@ cmdq_flush(struct cmd_q *cmdq) } cmdq->item = NULL; } + +/* Get default path using command queue. */ +const char * +cmdq_default_path(struct cmd_q *cmdq, const char *cwd) +{ + struct client *c = cmdq->client; + struct session *s; + const char *current; + + if ((s = cmd_current_session(cmdq, 0)) == NULL) + return (NULL); + + if (cwd == NULL) + cwd = options_get_string(&s->options, "default-path"); + + if (c != NULL && c->session == NULL && c->cwd != NULL) + current = c->cwd; + else if (s->curw != NULL) + current = get_proc_cwd(s->curw->window->active->fd); + else + current = NULL; + + return (cmd_default_path(s->cwd, current, cwd)); +} -- cgit From a0404b69026f420c8a1c35b6d017047f208cd322 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 10 Oct 2013 12:12:54 +0000 Subject: retcode -> retval for exit message. --- cmd-queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd-queue.c') diff --git a/cmd-queue.c b/cmd-queue.c index 1eacb4bc..b2030e69 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -143,7 +143,7 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...) evbuffer_add(c->stderr_data, "\n", 1); server_push_stderr(c); - c->retcode = 1; + c->retval = 1; } else { *msg = toupper((u_char) *msg); status_message_set(c, "%s", msg); -- cgit From 282c5f9644ed262ee15efbd3d072f7acc577da15 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 10 Oct 2013 12:26:34 +0000 Subject: Alter how tmux handles the working directory to internally use file descriptors rather than strings. - Each session still has a current working directory. - New sessions still get their working directory from the client that created them or its attached session if any. - New windows are created by default in the session working directory. - The -c flag to new, neww, splitw allows the working directory to be overridden. - The -c flag to attach let's the session working directory be changed. - The default-path option has been removed. To get the equivalent to default-path '.', do: bind c neww -c $PWD To get the equivalent of default-path '~', do: bind c neww -c ~ This also changes the client identify protocol to be a set of messages rather than one as well as some other changes that should make it easier to make backwards-compatible protocol changes in future. --- cmd-queue.c | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'cmd-queue.c') diff --git a/cmd-queue.c b/cmd-queue.c index b2030e69..bb3a09ec 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -283,27 +283,3 @@ cmdq_flush(struct cmd_q *cmdq) } cmdq->item = NULL; } - -/* Get default path using command queue. */ -const char * -cmdq_default_path(struct cmd_q *cmdq, const char *cwd) -{ - struct client *c = cmdq->client; - struct session *s; - const char *current; - - if ((s = cmd_current_session(cmdq, 0)) == NULL) - return (NULL); - - if (cwd == NULL) - cwd = options_get_string(&s->options, "default-path"); - - if (c != NULL && c->session == NULL && c->cwd != NULL) - current = c->cwd; - else if (s->curw != NULL) - current = get_proc_cwd(s->curw->window->active->fd); - else - current = NULL; - - return (cmd_default_path(s->cwd, current, cwd)); -} -- cgit