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 /job.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 'job.c')
-rw-r--r-- | job.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -41,13 +41,14 @@ struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs); /* Start a job running, if it isn't already. */ struct job * -job_run(const char *cmd, struct session *s, int cwd, +job_run(const char *cmd, struct session *s, const char *cwd, void (*callbackfn)(struct job *), void (*freefn)(void *), void *data) { struct job *job; struct environ *env; pid_t pid; int nullfd, out[2]; + const char *home; if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0) return (NULL); @@ -67,8 +68,10 @@ job_run(const char *cmd, struct session *s, int cwd, case 0: /* child */ clear_signals(1); - if (cwd != -1 && fchdir(cwd) != 0) - chdir("/"); + if (cwd == NULL || chdir(cwd) != 0) { + if ((home = find_home()) == NULL || chdir(home) != 0) + chdir("/"); + } environ_push(env); environ_free(env); |