summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-10-31 08:13:59 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-10-31 08:13:59 +0000
commit7e717b7c0bef4ea6f45816300dc8583a6e824290 (patch)
tree8e69b8b95496ce2a63ea8730df19d85dba84c775 /usr.bin/tmux/window.c
parent902466cba774a7c9c6d5cdd965302db1e4c04b0a (diff)
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 'usr.bin/tmux/window.c')
-rw-r--r--usr.bin/tmux/window.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 9bef3b69678..d53ef86d9cd 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.146 2015/10/27 15:58:43 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.147 2015/10/31 08:13:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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");