diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-11-27 16:12:30 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-11-27 16:12:30 +0000 |
commit | 16816c0030e3a95109214b66851ebc0b91ee6e87 (patch) | |
tree | 39673c8b50825c2a8d32cd9aba303ea3671a7ba3 | |
parent | 38e62cad30f7f4cc961b14e43c7b532a1cfe1f02 (diff) |
Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray
-rw-r--r-- | usr.bin/tmux/cfg.c | 13 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-source-file.c | 43 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
4 files changed, 34 insertions, 29 deletions
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c index b7265fafdbe..abf4af34afd 100644 --- a/usr.bin/tmux/cfg.c +++ b/usr.bin/tmux/cfg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cfg.c,v 1.17 2012/11/19 10:38:06 nicm Exp $ */ +/* $OpenBSD: cfg.c,v 1.18 2012/11/27 16:12:29 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c index 8f7149a8eac..be6529b83ae 100644 --- a/usr.bin/tmux/cmd-source-file.c +++ b/usr.bin/tmux/cmd-source-file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-source-file.c,v 1.13 2012/07/11 07:10:15 nicm Exp $ */ +/* $OpenBSD: cmd-source-file.c,v 1.14 2012/11/27 16:12:29 nicm Exp $ */ /* * Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org> @@ -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/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 2e39e6bfa14..710cae602c8 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.113 2012/11/26 11:35:28 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.114 2012/11/27 16:12:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 62b7e47223f..1af93e05867 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.364 2012/11/22 14:41:11 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.365 2012/11/27 16:12:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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 *); |