Correctly aggregate together errors from nested config files (with

source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray
This commit is contained in:
Nicholas Marriott 2012-11-27 16:12:29 +00:00
parent 4aa4e9fb26
commit 9b8998aeec
4 changed files with 30 additions and 25 deletions

11
cfg.c
View File

@ -34,9 +34,10 @@
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...); void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...); void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
char *cfg_cause; char *cfg_cause;
int cfg_finished; int cfg_finished;
struct causelist cfg_causes = ARRAY_INITIALIZER; int cfg_references;
struct causelist cfg_causes;
/* ARGSUSED */ /* ARGSUSED */
void printflike2 void printflike2
@ -89,6 +90,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
} }
n = 0; n = 0;
cfg_references++;
line = NULL; line = NULL;
retval = CMD_RETURN_NORMAL; retval = CMD_RETURN_NORMAL;
while ((buf = fgetln(f, &len))) { while ((buf = fgetln(f, &len))) {
@ -171,6 +174,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
} }
fclose(f); fclose(f);
cfg_references--;
return (retval); return (retval);
} }

View File

@ -42,35 +42,32 @@ enum cmd_retval
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct args *args = self->args; struct args *args = self->args;
struct causelist causes;
char *cause;
struct window_pane *wp;
int retval; int retval;
u_int i; 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); return (retval);
if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) { /*
wp = RB_MIN(sessions, &sessions)->curw->window->active; * We were called from the command-line in which case print the errors
window_pane_set_mode(wp, &window_copy_mode); * gathered here directly.
window_copy_init_for_output(wp); */
for (i = 0; i < ARRAY_LENGTH(&causes); i++) { for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&causes, i); cause = ARRAY_ITEM(&cfg_causes, i);
window_copy_add(wp, "%s", cause); ctx->print(ctx, "%s", cause);
free(cause); free(cause);
}
} else {
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
cause = ARRAY_ITEM(&causes, i);
ctx->print(ctx, "%s", cause);
free(cause);
}
} }
ARRAY_FREE(&causes); ARRAY_FREE(&cfg_causes);
return (retval); return (retval);
} }

2
tmux.c
View File

@ -330,6 +330,8 @@ main(int argc, char **argv)
options_init(&global_w_options, NULL); options_init(&global_w_options, NULL);
options_table_populate_tree(window_options_table, &global_w_options); 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. */ /* Enable UTF-8 if the first client is on UTF-8 terminal. */
if (flags & IDENTIFY_UTF8) { if (flags & IDENTIFY_UTF8) {
options_set_number(&global_s_options, "status-utf8", 1); options_set_number(&global_s_options, "status-utf8", 1);

1
tmux.h
View File

@ -1517,6 +1517,7 @@ __dead void shell_exec(const char *, const char *);
/* cfg.c */ /* cfg.c */
extern int cfg_finished; extern int cfg_finished;
extern int cfg_references;
extern struct causelist cfg_causes; extern struct causelist cfg_causes;
void printflike2 cfg_add_cause(struct causelist *, const char *, ...); void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
int load_cfg(const char *, struct cmd_ctx *, struct causelist *); int load_cfg(const char *, struct cmd_ctx *, struct causelist *);