diff --git a/cfg.c b/cfg.c index ae7d9a30..3da6ea4d 100644 --- a/cfg.c +++ b/cfg.c @@ -34,9 +34,10 @@ void printflike2 cfg_print(struct cmd_ctx *, const char *, ...); void printflike2 cfg_error(struct cmd_ctx *, const char *, ...); -char *cfg_cause; -int cfg_finished; -struct causelist cfg_causes = ARRAY_INITIALIZER; +char *cfg_cause; +int cfg_finished; +int cfg_references; +struct causelist cfg_causes; /* ARGSUSED */ void printflike2 @@ -89,6 +90,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) } n = 0; + cfg_references++; + line = NULL; retval = CMD_RETURN_NORMAL; while ((buf = fgetln(f, &len))) { @@ -171,6 +174,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) } fclose(f); + cfg_references--; + return (retval); } diff --git a/cmd-source-file.c b/cmd-source-file.c index 758f959a..0a180d89 100644 --- a/cmd-source-file.c +++ b/cmd-source-file.c @@ -42,35 +42,32 @@ enum cmd_retval cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; - struct causelist causes; - char *cause; - struct window_pane *wp; int retval; u_int i; + char *cause; - ARRAY_INIT(&causes); + retval = load_cfg(args->argv[0], ctx, &cfg_causes); - retval = load_cfg(args->argv[0], ctx, &causes); - if (ARRAY_EMPTY(&causes)) + /* + * If the context for the cmdclient came from tmux's configuration + * file, then return the status of this command now, regardless of the + * error condition. Any errors from parsing a configuration file at + * startup will be handled for us by the server. + */ + if (cfg_references > 0 || + (ctx->curclient == NULL && ctx->cmdclient == NULL)) return (retval); - if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) { - wp = RB_MIN(sessions, &sessions)->curw->window->active; - window_pane_set_mode(wp, &window_copy_mode); - window_copy_init_for_output(wp); - for (i = 0; i < ARRAY_LENGTH(&causes); i++) { - cause = ARRAY_ITEM(&causes, i); - window_copy_add(wp, "%s", cause); - free(cause); - } - } else { - for (i = 0; i < ARRAY_LENGTH(&causes); i++) { - cause = ARRAY_ITEM(&causes, i); - ctx->print(ctx, "%s", cause); - free(cause); - } + /* + * We were called from the command-line in which case print the errors + * gathered here directly. + */ + for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) { + cause = ARRAY_ITEM(&cfg_causes, i); + ctx->print(ctx, "%s", cause); + free(cause); } - ARRAY_FREE(&causes); + ARRAY_FREE(&cfg_causes); return (retval); } diff --git a/tmux.c b/tmux.c index 7bce10ec..2428a404 100644 --- a/tmux.c +++ b/tmux.c @@ -330,6 +330,8 @@ main(int argc, char **argv) options_init(&global_w_options, NULL); options_table_populate_tree(window_options_table, &global_w_options); + ARRAY_INIT(&cfg_causes); + /* Enable UTF-8 if the first client is on UTF-8 terminal. */ if (flags & IDENTIFY_UTF8) { options_set_number(&global_s_options, "status-utf8", 1); diff --git a/tmux.h b/tmux.h index 98677f78..2b5f19d8 100644 --- a/tmux.h +++ b/tmux.h @@ -1517,6 +1517,7 @@ __dead void shell_exec(const char *, const char *); /* cfg.c */ extern int cfg_finished; +extern int cfg_references; extern struct causelist cfg_causes; void printflike2 cfg_add_cause(struct causelist *, const char *, ...); int load_cfg(const char *, struct cmd_ctx *, struct causelist *);