From 01defc9f4965bb174e1d1295754d5a8695683054 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 31 Oct 2015 08:13:58 +0000 Subject: 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). --- cmd-attach-session.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'cmd-attach-session.c') diff --git a/cmd-attach-session.c b/cmd-attach-session.c index c570358c..b339b890 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -51,9 +51,8 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, struct window_pane *wp = NULL; const char *update; char *cause; - int fd; struct format_tree *ft; - char *cp; + char *cwd; if (RB_EMPTY(&sessions)) { cmdq_error(cmdq, "no sessions"); @@ -97,18 +96,17 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, ft = format_create(); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL, NULL); - cp = format_expand(ft, cflag); + cwd = format_expand(ft, cflag); format_free(ft); - fd = open(cp, O_RDONLY|O_DIRECTORY); - free(cp); - if (fd == -1) { + if (access(cwd, X_OK) != 0) { + free((void *)cwd); cmdq_error(cmdq, "bad working directory: %s", strerror(errno)); return (CMD_RETURN_ERROR); } - close(s->cwd); - s->cwd = fd; + free((void *)s->cwd); + s->cwd = cwd; } if (c->session != NULL) { -- cgit