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-split-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-split-window.c')
-rw-r--r-- | cmd-split-window.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/cmd-split-window.c b/cmd-split-window.c index 75b8eeb6..6adb19a8 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -53,10 +53,10 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) struct window *w; struct window_pane *wp, *new_wp = NULL; struct environ *env; - const char *cmd, *path, *shell, *template; + const char *cmd, *path, *shell, *template, *cwd, *to_free; char **argv, *cause, *new_cause, *cp; u_int hlimit; - int argc, size, percentage, cwd, fd = -1; + int argc, size, percentage; enum layout_type type; struct layout_cell *lc; struct format_tree *ft; @@ -86,24 +86,20 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) argv = args->argv; } + 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')); + to_free = 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 @@ -188,8 +184,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) } notify_window_layout_changed(w); - if (fd != -1) - close(fd); + if (to_free != NULL) + free((void *)to_free); return (CMD_RETURN_NORMAL); error: @@ -200,7 +196,8 @@ error: } cmdq_error(cmdq, "create pane failed: %s", cause); free(cause); - if (fd != -1) - close(fd); + + if (to_free != NULL) + free((void *)to_free); return (CMD_RETURN_ERROR); } |