From 5330a2a85d69647f4f402c5b1fe85dc548ce5416 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 9 Jan 2017 19:27:00 +0000 Subject: [PATCH 1/2] Run the source-file pattern through glob(3). --- cfg.c | 10 +++++----- cmd-source-file.c | 28 ++++++++++++++++++---------- tmux.1 | 5 ++++- tmux.h | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/cfg.c b/cfg.c index 91c16fa4..63413124 100644 --- a/cfg.c +++ b/cfg.c @@ -28,11 +28,11 @@ #include "tmux.h" -char *cfg_file; -int cfg_finished; -static char **cfg_causes; -static u_int cfg_ncauses; -struct client *cfg_client; +char *cfg_file; +int cfg_finished; +static char **cfg_causes; +static u_int cfg_ncauses; +struct client *cfg_client; static enum cmd_retval cfg_done(__unused struct cmdq_item *item, __unused void *data) diff --git a/cmd-source-file.c b/cmd-source-file.c index d2178692..fc5de58b 100644 --- a/cmd-source-file.c +++ b/cmd-source-file.c @@ -18,7 +18,10 @@ #include +#include +#include #include +#include #include "tmux.h" @@ -48,23 +51,28 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) struct client *c = item->client; int quiet; struct cmdq_item *new_item; + enum cmd_retval retval; + glob_t g; + int i; - quiet = args_has(args, 'q'); - switch (load_cfg(args->argv[0], c, item, quiet)) { - case -1: - if (cfg_finished) - cfg_print_causes(item); + if (glob(args->argv[0], 0, NULL, &g) != 0) { + cmdq_error(item, "%s: %s", args->argv[0], strerror(errno)); return (CMD_RETURN_ERROR); - case 0: - if (cfg_finished) - cfg_print_causes(item); - return (CMD_RETURN_NORMAL); + } + quiet = args_has(args, 'q'); + + retval = CMD_RETURN_NORMAL; + for (i = 0; i < g.gl_pathc; i++) { + if (load_cfg(g.gl_pathv[i], c, item, quiet) != 0) + retval = CMD_RETURN_ERROR; } if (cfg_finished) { new_item = cmdq_get_callback(cmd_source_file_done, NULL); cmdq_insert_after(item, new_item); } - return (CMD_RETURN_NORMAL); + + globfree(&g); + return (retval); } static enum cmd_retval diff --git a/tmux.1 b/tmux.1 index 234627fc..a5be4617 100644 --- a/tmux.1 +++ b/tmux.1 @@ -921,7 +921,10 @@ show debugging information about jobs and terminals. .Xc .D1 (alias: Ic source ) Execute commands from -.Ar path . +.Ar path +(which may be a +.Xr glob 3 +pattern). If .Fl q is given, no error will be returned if diff --git a/tmux.h b/tmux.h index 25473ba0..89794ecd 100644 --- a/tmux.h +++ b/tmux.h @@ -76,7 +76,7 @@ struct tmuxproc; #define READ_CHANGE_HITS 3 -/* Attribute to make gcc check printf-like arguments. */ +/* Attribute to make GCC check printf-like arguments. */ #define printflike(a, b) __attribute__ ((format (printf, a, b))) /* Number of items in array. */ From 561b5c6fdbdafae52ac5b4bd963f0d75af344c5b Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 9 Jan 2017 19:29:12 +0000 Subject: [PATCH 2/2] source-file -q needs to apply to glob(3) too. --- cmd-source-file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd-source-file.c b/cmd-source-file.c index fc5de58b..4ca47193 100644 --- a/cmd-source-file.c +++ b/cmd-source-file.c @@ -55,11 +55,13 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) glob_t g; int i; + quiet = args_has(args, 'q'); if (glob(args->argv[0], 0, NULL, &g) != 0) { + if (quiet && errno == ENOENT) + return (CMD_RETURN_NORMAL); cmdq_error(item, "%s: %s", args->argv[0], strerror(errno)); return (CMD_RETURN_ERROR); } - quiet = args_has(args, 'q'); retval = CMD_RETURN_NORMAL; for (i = 0; i < g.gl_pathc; i++) {