diff options
author | tim <tim> | 2016-05-12 16:05:33 +0000 |
---|---|---|
committer | tim <tim> | 2016-05-12 16:05:33 +0000 |
commit | fdd368a2945f1f5cbd1cd2a858c00ebffdbf7e46 (patch) | |
tree | d25e3aaaa189854425bac52b23f64be81ebf461b /cfg.c | |
parent | 9715c61de0d7891cfe584ae1f63904a50abc2a54 (diff) |
- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.
Input and OK nicm@
Diffstat (limited to 'cfg.c')
-rw-r--r-- | cfg.c | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -48,8 +48,8 @@ set_cfg_file(const char *path) void start_cfg(void) { - char *cause = NULL; const char *home; + int quiet = 0; cfg_cmd_q = cmdq_new(NULL); cfg_cmd_q->emptyfn = cfg_default_done; @@ -61,28 +61,20 @@ start_cfg(void) if (cfg_client != NULL) cfg_client->references++; - if (access(TMUX_CONF, R_OK) == 0) { - if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) - cfg_add_cause("%s: %s", TMUX_CONF, cause); - } else if (errno != ENOENT) - cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno)); + load_cfg(TMUX_CONF, cfg_cmd_q, 1); if (cfg_file == NULL && (home = find_home()) != NULL) { xasprintf(&cfg_file, "%s/.tmux.conf", home); - if (access(cfg_file, R_OK) != 0 && errno == ENOENT) { - free(cfg_file); - cfg_file = NULL; - } + quiet = 1; } - if (cfg_file != NULL && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) - cfg_add_cause("%s: %s", cfg_file, cause); - free(cause); + if (cfg_file != NULL) + load_cfg(cfg_file, cfg_cmd_q, quiet); cmdq_continue(cfg_cmd_q); } int -load_cfg(const char *path, struct cmd_q *cmdq, char **cause) +load_cfg(const char *path, struct cmd_q *cmdq, int quiet) { FILE *f; char delim[3] = { '\\', '\\', '\0' }; @@ -93,7 +85,9 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause) log_debug("loading %s", path); if ((f = fopen(path, "rb")) == NULL) { - xasprintf(cause, "%s: %s", path, strerror(errno)); + if (errno == ENOENT && quiet) + return (0); + cfg_add_cause("%s: %s", path, strerror(errno)); return (-1); } |