diff options
author | nicm <nicm> | 2015-10-31 08:13:58 +0000 |
---|---|---|
committer | nicm <nicm> | 2015-10-31 08:13:58 +0000 |
commit | 01defc9f4965bb174e1d1295754d5a8695683054 (patch) | |
tree | 6f8095583d6176dffe130d6ff3b5dbc3f0e3150d /cmd-new-window.c | |
parent | 45f3cea263d1f99912cd6b353c91ccb872c26a71 (diff) | |
download | rtmux-01defc9f4965bb174e1d1295754d5a8695683054.tar.gz rtmux-01defc9f4965bb174e1d1295754d5a8695683054.tar.bz2 rtmux-01defc9f4965bb174e1d1295754d5a8695683054.zip |
Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).
Diffstat (limited to 'cmd-new-window.c')
-rw-r--r-- | cmd-new-window.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/cmd-new-window.c b/cmd-new-window.c index 70e70c68..a5085fff 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -49,9 +49,9 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) struct args *args = self->args; struct session *s; struct winlink *wl; - const char *cmd, *path, *template; + const char *cmd, *path, *template, *cwd, *to_free; char **argv, *cause, *cp; - int argc, idx, detached, cwd, fd = -1; + int argc, idx, detached; struct format_tree *ft; struct environ_entry *envent; @@ -92,24 +92,20 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) if (envent != NULL) path = envent->value; + to_free = NULL; if (args_has(args, 'c')) { ft = format_create(); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL, NULL); - cp = format_expand(ft, args_get(args, 'c')); + cwd = format_expand(ft, args_get(args, 'c')); format_free(ft); - if (cp != NULL && *cp != '\0') { - fd = open(cp, O_RDONLY|O_DIRECTORY); - free(cp); - if (fd == -1) { - cmdq_error(cmdq, "bad working directory: %s", - strerror(errno)); - return (CMD_RETURN_ERROR); - } - } else - free(cp); - cwd = fd; + if (access(cwd, X_OK) != 0) { + free((void *)cwd); + cmdq_error(cmdq, "bad working directory: %s", + strerror(errno)); + return (CMD_RETURN_ERROR); + } } else if (cmdq->client != NULL && cmdq->client->session == NULL) cwd = cmdq->client->cwd; else @@ -165,12 +161,12 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) format_free(ft); } - if (fd != -1) - close(fd); + if (to_free != NULL) + free((void *)to_free); return (CMD_RETURN_NORMAL); error: - if (fd != -1) - close(fd); + if (to_free != NULL) + free((void *)to_free); return (CMD_RETURN_ERROR); } |