From 4a51a9d9d5b43f6b576692f9ce5f5ccfa425f806 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 25 Apr 2017 14:46:23 +0000 Subject: [PATCH 1/2] Block the initial client if there is one until the configuration file has finished loading. --- cfg.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/cfg.c b/cfg.c index f98d5f0b..9ade397e 100644 --- a/cfg.c +++ b/cfg.c @@ -28,10 +28,19 @@ #include "tmux.h" -static char *cfg_file; -int cfg_finished; -static char **cfg_causes; -static u_int cfg_ncauses; +static char *cfg_file; +int cfg_finished; +static char **cfg_causes; +static u_int cfg_ncauses; +static struct cmdq_item *cfg_item; + +static enum cmd_retval +cfg_client_done(__unused struct cmdq_item *item, __unused void *data) +{ + if (!cfg_finished) + return (CMD_RETURN_WAIT); + return (CMD_RETURN_NORMAL); +} static enum cmd_retval cfg_done(__unused struct cmdq_item *item, __unused void *data) @@ -43,6 +52,9 @@ cfg_done(__unused struct cmdq_item *item, __unused void *data) if (!RB_EMPTY(&sessions)) cfg_show_causes(RB_MIN(sessions, &sessions)); + if (cfg_item != NULL) + cfg_item->flags &= ~CMDQ_WAITING; + status_prompt_load_history(); return (CMD_RETURN_NORMAL); @@ -60,12 +72,24 @@ start_cfg(void) { const char *home; int quiet = 0; + struct client *c; /* - * Note that the configuration files are loaded without a client, so - * NULL is passed into load_cfg() which means that commands run in the - * global queue and item->client is NULL for all commands. + * Configuration files are loaded without a client, so NULL is passed + * into load_cfg() and commands run in the global queue with + * item->client NULL. + * + * However, we must block the initial client (but just the initial + * client) so that its command runs after the configuration is loaded. + * Because start_cfg() is called so early, we can be sure the client's + * command queue is currently empty and our callback will be at the + * front - we need to get in before MSG_COMMAND. */ + c = TAILQ_FIRST(&clients); + if (c != NULL) { + cfg_item = cmdq_get_callback(cfg_client_done, NULL); + cmdq_append(c, cfg_item); + } load_cfg(TMUX_CONF, NULL, NULL, 1); From c48d09ec8870ac218d6cc2bbec638d59839eda27 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 25 Apr 2017 15:35:10 +0000 Subject: [PATCH 2/2] Do not update TERM into config file parsing has finished. --- cmd-respawn-pane.c | 2 +- cmd-respawn-window.c | 2 +- cmd-split-window.c | 2 +- environ.c | 8 +++++--- job.c | 7 ++++++- session.c | 2 +- tmux.h | 2 +- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c index defdc77e..a1178147 100644 --- a/cmd-respawn-pane.c +++ b/cmd-respawn-pane.c @@ -77,7 +77,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; - env = environ_for_session(s); + env = environ_for_session(s, 0); if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { cmdq_error(item, "respawn pane failed: %s", cause); diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c index f9edbec7..48e6a97f 100644 --- a/cmd-respawn-window.c +++ b/cmd-respawn-window.c @@ -81,7 +81,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; - env = environ_for_session(s); + env = environ_for_session(s, 0); if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { cmdq_error(item, "respawn window failed: %s", cause); diff --git a/cmd-split-window.c b/cmd-split-window.c index 7de16ac2..029e6900 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -144,7 +144,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; - env = environ_for_session(s); + env = environ_for_session(s, 0); if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, env, s->tio, &cause) != 0) { environ_free(env); diff --git a/environ.c b/environ.c index 868324ed..d884330e 100644 --- a/environ.c +++ b/environ.c @@ -222,7 +222,7 @@ environ_log(struct environ *env, const char *prefix) /* Create initial environment for new child. */ struct environ * -environ_for_session(struct session *s) +environ_for_session(struct session *s, int no_TERM) { struct environ *env; const char *value; @@ -233,8 +233,10 @@ environ_for_session(struct session *s) if (s != NULL) environ_copy(s->environ, env); - value = options_get_string(global_options, "default-terminal"); - environ_set(env, "TERM", "%s", value); + if (!no_TERM) { + value = options_get_string(global_options, "default-terminal"); + environ_set(env, "TERM", "%s", value); + } if (s != NULL) idx = s->id; diff --git a/job.c b/job.c index caf5db52..7065a671 100644 --- a/job.c +++ b/job.c @@ -55,7 +55,12 @@ job_run(const char *cmd, struct session *s, const char *cwd, if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0) return (NULL); - env = environ_for_session(s); + /* + * Do not set TERM during .tmux.conf, it is nice to be able to use + * if-shell to decide on default-terminal based on outside TERM. + */ + env = environ_for_session(s, !cfg_finished); + switch (pid = fork()) { case -1: environ_free(env); diff --git a/session.c b/session.c index cb8ed1eb..eee478dd 100644 --- a/session.c +++ b/session.c @@ -360,7 +360,7 @@ session_new(struct session *s, const char *name, int argc, char **argv, shell = _PATH_BSHELL; hlimit = options_get_number(s->options, "history-limit"); - env = environ_for_session(s); + env = environ_for_session(s, 0); w = window_create_spawn(name, argc, argv, path, shell, cwd, env, s->tio, s->sx, s->sy, hlimit, cause); if (w == NULL) { diff --git a/tmux.h b/tmux.h index 0e64b1bb..b9ee9516 100644 --- a/tmux.h +++ b/tmux.h @@ -1612,7 +1612,7 @@ void environ_unset(struct environ *, const char *); void environ_update(struct options *, struct environ *, struct environ *); void environ_push(struct environ *); void environ_log(struct environ *, const char *); -struct environ *environ_for_session(struct session *); +struct environ *environ_for_session(struct session *, int); /* tty.c */ void tty_create_log(void);