diff options
author | 2021-02-22 08:18:13 +0000 | |
---|---|---|
committer | 2021-02-22 08:18:13 +0000 | |
commit | b8e6286c25d8be71887d9786f8ae1038e8cd9fac (patch) | |
tree | 649253b843def857dab3d5004e5ee7f54f1edfed /usr.bin/tmux/tmux.c | |
parent | There are many format variables now so allocating all the default ones (diff) | |
download | wireguard-openbsd-b8e6286c25d8be71887d9786f8ae1038e8cd9fac.tar.xz wireguard-openbsd-b8e6286c25d8be71887d9786f8ae1038e8cd9fac.zip |
Move config file path expansion much earlier, keep the list of paths
around rather than freeing later, and add a config_files format variable
containing it. Suggested by kn@ a while back.
Diffstat (limited to 'usr.bin/tmux/tmux.c')
-rw-r--r-- | usr.bin/tmux/tmux.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 518d784c1d5..91c0e5dbd88 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.204 2021/01/17 16:17:41 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.205 2021/02/22 08:18:13 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -142,11 +142,12 @@ expand_path(const char *path, const char *home) return (xstrdup(path)); } -void -expand_paths(const char *s, char ***paths, u_int *n) +static void +expand_paths(const char *s, char ***paths, u_int *n, int ignore_errors) { const char *home = find_home(); char *copy, *next, *tmp, resolved[PATH_MAX], *expanded; + char *path; u_int i; *paths = NULL; @@ -162,20 +163,26 @@ expand_paths(const char *s, char ***paths, u_int *n) if (realpath(expanded, resolved) == NULL) { log_debug("%s: realpath(\"%s\") failed: %s", __func__, expanded, strerror(errno)); + if (ignore_errors) { + free(expanded); + continue; + } + path = expanded; + } else { + path = xstrdup(resolved); free(expanded); - continue; } - free(expanded); for (i = 0; i < *n; i++) { - if (strcmp(resolved, (*paths)[i]) == 0) + if (strcmp(path, (*paths)[i]) == 0) break; } if (i != *n) { - log_debug("%s: duplicate path: %s", __func__, resolved); + log_debug("%s: duplicate path: %s", __func__, path); + free(path); continue; } *paths = xreallocarray(*paths, (*n) + 1, sizeof *paths); - (*paths)[(*n)++] = xstrdup(resolved); + (*paths)[(*n)++] = path; } free(copy); } @@ -193,7 +200,7 @@ make_label(const char *label, char **cause) label = "default"; uid = getuid(); - expand_paths(TMUX_SOCK, &paths, &n); + expand_paths(TMUX_SOCK, &paths, &n, 1); if (n == 0) { xasprintf(cause, "no suitable socket path"); return (NULL); @@ -330,10 +337,11 @@ main(int argc, char **argv) { char *path = NULL, *label = NULL; char *cause, **var; - const char *s, *shell, *cwd; + const char *s, *cwd; int opt, keys, feat = 0; uint64_t flags = 0; const struct options_table_entry *oe; + u_int i; if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL && setlocale(LC_CTYPE, "C.UTF-8") == NULL) { @@ -349,6 +357,7 @@ main(int argc, char **argv) if (**argv == '-') flags = CLIENT_LOGIN; + expand_paths(TMUX_CONF, &cfg_files, &cfg_nfiles, 1); while ((opt = getopt(argc, argv, "2c:CDdf:lL:NqS:T:uUvV")) != -1) { switch (opt) { @@ -368,7 +377,11 @@ main(int argc, char **argv) flags |= CLIENT_CONTROL; break; case 'f': - set_cfg_file(optarg); + for (i = 0; i < cfg_nfiles; i++) + free(cfg_files[i]); + free(cfg_files); + expand_paths(optarg, &cfg_files, &cfg_nfiles, 0); + cfg_quiet = 0; break; case 'V': printf("%s %s\n", getprogname(), getversion()); @@ -460,8 +473,8 @@ main(int argc, char **argv) * The default shell comes from SHELL or from the user's passwd entry * if available. */ - shell = getshell(); - options_set_string(global_s_options, "default-shell", 0, "%s", shell); + options_set_string(global_s_options, "default-shell", 0, "%s", + getshell()); /* Override keys to vi if VISUAL or EDITOR are set. */ if ((s = getenv("VISUAL")) != NULL || (s = getenv("EDITOR")) != NULL) { |