aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authornicm <nicm>2015-10-31 08:13:58 +0000
committernicm <nicm>2015-10-31 08:13:58 +0000
commit01defc9f4965bb174e1d1295754d5a8695683054 (patch)
tree6f8095583d6176dffe130d6ff3b5dbc3f0e3150d /window.c
parent45f3cea263d1f99912cd6b353c91ccb872c26a71 (diff)
downloadrtmux-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 'window.c')
-rw-r--r--window.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/window.c b/window.c
index baaaa0f8..49408297 100644
--- a/window.c
+++ b/window.c
@@ -316,8 +316,8 @@ window_create1(u_int sx, u_int sy)
struct window *
window_create(const char *name, int argc, char **argv, const char *path,
- const char *shell, int cwd, struct environ *env, struct termios *tio,
- u_int sx, u_int sy, u_int hlimit, char **cause)
+ const char *shell, const char *cwd, struct environ *env,
+ struct termios *tio, u_int sx, u_int sy, u_int hlimit, char **cause)
{
struct window *w;
struct window_pane *wp;
@@ -736,7 +736,7 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->argc = 0;
wp->argv = NULL;
wp->shell = NULL;
- wp->cwd = -1;
+ wp->cwd = NULL;
wp->fd = -1;
wp->event = NULL;
@@ -796,7 +796,7 @@ window_pane_destroy(struct window_pane *wp)
RB_REMOVE(window_pane_tree, &all_window_panes, wp);
- close(wp->cwd);
+ free((void *)wp->cwd);
free(wp->shell);
cmd_free_argv(wp->argc, wp->argv);
free(wp);
@@ -804,12 +804,12 @@ window_pane_destroy(struct window_pane *wp)
int
window_pane_spawn(struct window_pane *wp, int argc, char **argv,
- const char *path, const char *shell, int cwd, struct environ *env,
+ const char *path, const char *shell, const char *cwd, struct environ *env,
struct termios *tio, char **cause)
{
struct winsize ws;
char *argv0, *cmd, **argvp, paneid[16];
- const char *ptr, *first;
+ const char *ptr, *first, *home;
struct termios tio2;
int i;
@@ -826,9 +826,9 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv,
free(wp->shell);
wp->shell = xstrdup(shell);
}
- if (cwd != -1) {
- close(wp->cwd);
- wp->cwd = dup(cwd);
+ if (cwd != NULL) {
+ free((void *)wp->cwd);
+ wp->cwd = xstrdup(cwd);
}
cmd = cmd_stringify_argv(wp->argc, wp->argv);
@@ -847,8 +847,10 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv,
free(cmd);
return (-1);
case 0:
- if (fchdir(wp->cwd) != 0)
- chdir("/");
+ if (chdir(wp->cwd) != 0) {
+ if ((home = find_home()) == NULL || chdir(home) != 0)
+ chdir("/");
+ }
if (tcgetattr(STDIN_FILENO, &tio2) != 0)
fatal("tcgetattr failed");