diff options
author | 2016-05-12 16:05:33 +0000 | |
---|---|---|
committer | 2016-05-12 16:05:33 +0000 | |
commit | 59c70a5f496903cd63171d4b0571fc530f9ac47a (patch) | |
tree | b0ba2f331668a3447170fc84db239c9735e4a3fa | |
parent | Using a 3-word buffer in the openbsd.randomdata segment, XOR swizzle (diff) | |
download | wireguard-openbsd-59c70a5f496903cd63171d4b0571fc530f9ac47a.tar.xz wireguard-openbsd-59c70a5f496903cd63171d4b0571fc530f9ac47a.zip |
- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.
Input and OK nicm@
-rw-r--r-- | usr.bin/tmux/cfg.c | 26 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-source-file.c | 22 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 14 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 |
4 files changed, 33 insertions, 33 deletions
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c index 72ece86bbf6..81518a58484 100644 --- a/usr.bin/tmux/cfg.c +++ b/usr.bin/tmux/cfg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cfg.c,v 1.44 2016/01/19 15:59:12 nicm Exp $ */ +/* $OpenBSD: cfg.c,v 1.45 2016/05/12 16:05:33 tim Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -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); } diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c index 31a1eaca606..1206af6d818 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.24 2016/04/29 14:05:24 nicm Exp $ */ +/* $OpenBSD: cmd-source-file.c,v 1.25 2016/05/12 16:05:33 tim Exp $ */ /* * Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org> @@ -34,8 +34,8 @@ const struct cmd_entry cmd_source_file_entry = { .name = "source-file", .alias = "source", - .args = { "", 1, 1 }, - .usage = "path", + .args = { "q", 1, 1 }, + .usage = "[-q] path", .flags = 0, .exec = cmd_source_file_exec @@ -46,28 +46,26 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct cmd_q *cmdq1; - char *cause; + int quiet; cmdq1 = cmdq_new(cmdq->client); cmdq1->flags |= cmdq->flags & CMD_Q_NOHOOKS; cmdq1->emptyfn = cmd_source_file_done; cmdq1->data = cmdq; - switch (load_cfg(args->argv[0], cmdq1, &cause)) { + quiet = args_has(args, 'q'); + switch (load_cfg(args->argv[0], cmdq1, quiet)) { case -1: + cmdq_free(cmdq1); if (cfg_references == 0) { - cmdq_free(cmdq1); - cmdq_error(cmdq, "%s", cause); - free(cause); + cfg_print_causes(cmdq); return (CMD_RETURN_ERROR); } - cfg_add_cause("%s", cause); - free(cause); - /* FALLTHROUGH */ + return (CMD_RETURN_NORMAL); case 0: + cmdq_free(cmdq1); if (cfg_references == 0) cfg_print_causes(cmdq); - cmdq_free(cmdq1); return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 459c11efa82..3db090908a2 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.487 2016/05/01 11:46:12 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.488 2016/05/12 16:05:33 tim Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 1 2016 $ +.Dd $Mdocdate: May 12 2016 $ .Dt TMUX 1 .Os .Sh NAME @@ -913,10 +913,18 @@ display the log for and .Fl T show debugging information about jobs and terminals. -.It Ic source-file Ar path +.It Xo Ic source-file +.Op Fl q +.Ar path +.Xc .D1 (alias: Ic source ) Execute commands from .Ar path . +If +.Fl q +is given, no error will be returned if +.Ar path +does not exist. .It Ic start-server .D1 (alias: Ic start ) Start the diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 46ecf21ade8..5a24d0e03ab 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.629 2016/05/01 13:39:05 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.630 2016/05/12 16:05:33 tim Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1555,7 +1555,7 @@ extern int cfg_finished; extern int cfg_references; extern struct client *cfg_client; void start_cfg(void); -int load_cfg(const char *, struct cmd_q *, char **); +int load_cfg(const char *, struct cmd_q *, int); void set_cfg_file(const char *); void printflike(1, 2) cfg_add_cause(const char *, ...); void cfg_print_causes(struct cmd_q *); |