mirror of
https://github.com/tmux/tmux.git
synced 2025-01-12 19:39:04 +00:00
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:
parent
4aa4e9fb26
commit
9b8998aeec
11
cfg.c
11
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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
2
tmux.c
2
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);
|
||||
|
1
tmux.h
1
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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user