summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2014-04-17 13:03:00 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2014-04-17 13:03:00 +0000
commit7fd8724d3d2c95a5578620be50d23402ddd64d07 (patch)
treeabde01f2369bba414dd95ef4af82185048d5d81d /usr.bin/tmux
parent831b6ee9333e424fa301c2bb85a807c0c47b0697 (diff)
Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J Raynor.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-new-session.c15
-rw-r--r--usr.bin/tmux/cmd-new-window.c18
-rw-r--r--usr.bin/tmux/cmd-respawn-pane.c17
-rw-r--r--usr.bin/tmux/cmd-respawn-window.c17
-rw-r--r--usr.bin/tmux/cmd-split-window.c16
-rw-r--r--usr.bin/tmux/session.c17
-rw-r--r--usr.bin/tmux/tmux.h18
-rw-r--r--usr.bin/tmux/window.c16
8 files changed, 96 insertions, 38 deletions
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index cc39946d0d9..c1b49fe1e9e 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.58 2014/04/17 11:38:35 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.59 2014/04/17 13:02:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -54,10 +54,12 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
struct environ env;
struct termios tio, *tiop;
const char *newname, *target, *update, *errstr, *template;
+ const char *path;
char *cmd, *cause, *cp;
int detached, already_attached, idx, cwd, fd = -1;
u_int sx, sy;
struct format_tree *ft;
+ struct environ_entry *envent;
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
cmdq_error(cmdq, "command or window name given with target");
@@ -188,6 +190,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
else
cmd = options_get_string(&global_s_options, "default-command");
+ path = NULL;
+ if (c != NULL && c->session == NULL)
+ envent = environ_find(&c->environ, "PATH");
+ else
+ envent = environ_find(&global_environ, "PATH");
+ if (envent != NULL)
+ path = envent->value;
+
/* Construct the environment. */
environ_init(&env);
update = options_get_string(&global_s_options, "update-environment");
@@ -196,7 +206,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
/* Create the new session. */
idx = -1 - options_get_number(&global_s_options, "base-index");
- s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
+ s = session_create(newname, cmd, path, cwd, &env, tiop, idx, sx, sy,
+ &cause);
if (s == NULL) {
cmdq_error(cmdq, "create session failed: %s", cause);
free(cause);
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index 4851540d552..770e20e721f 100644
--- a/usr.bin/tmux/cmd-new-window.c
+++ b/usr.bin/tmux/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-window.c,v 1.38 2013/11/23 09:18:29 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.39 2014/04/17 13:02:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -49,10 +49,11 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct session *s;
struct winlink *wl;
struct client *c;
- const char *cmd, *template;
+ const char *cmd, *path, *template;
char *cause, *cp;
int idx, last, detached, cwd, fd = -1;
struct format_tree *ft;
+ struct environ_entry *envent;
if (args_has(args, 'a')) {
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
@@ -77,7 +78,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
server_unlink_window(s, wl);
}
} else {
- if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &s)) == -2)
+ idx = cmd_find_index(cmdq, args_get(args, 't'), &s);
+ if (idx == -2)
return (CMD_RETURN_ERROR);
}
detached = args_has(args, 'd');
@@ -87,6 +89,14 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
else
cmd = args->argv[0];
+ path = NULL;
+ if (cmdq->client != NULL && cmdq->client->session == NULL)
+ envent = environ_find(&cmdq->client->environ, "PATH");
+ else
+ envent = environ_find(&s->environ, "PATH");
+ if (envent != NULL)
+ path = envent->value;
+
if (args_has(args, 'c')) {
ft = format_create();
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
@@ -135,7 +145,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
if (idx == -1)
idx = -1 - options_get_number(&s->options, "base-index");
- wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
+ wl = session_new(s, args_get(args, 'n'), cmd, path, cwd, idx, &cause);
if (wl == NULL) {
cmdq_error(cmdq, "create window failed: %s", cause);
free(cause);
diff --git a/usr.bin/tmux/cmd-respawn-pane.c b/usr.bin/tmux/cmd-respawn-pane.c
index 32c996ae0f3..986cd86c088 100644
--- a/usr.bin/tmux/cmd-respawn-pane.c
+++ b/usr.bin/tmux/cmd-respawn-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-respawn-pane.c,v 1.10 2013/10/10 12:29:53 nicm Exp $ */
+/* $OpenBSD: cmd-respawn-pane.c,v 1.11 2014/04/17 13:02:59 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -48,9 +48,10 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
struct window_pane *wp;
struct session *s;
struct environ env;
- const char *cmd;
+ const char *cmd, *path;
char *cause;
u_int idx;
+ struct environ_entry *envent;
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
@@ -77,7 +78,17 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
cmd = args->argv[0];
else
cmd = NULL;
- if (window_pane_spawn(wp, cmd, NULL, -1, &env, s->tio, &cause) != 0) {
+
+ path = NULL;
+ if (cmdq->client != NULL && cmdq->client->session == NULL)
+ envent = environ_find(&cmdq->client->environ, "PATH");
+ else
+ envent = environ_find(&s->environ, "PATH");
+ if (envent != NULL)
+ path = envent->value;
+
+ if (window_pane_spawn(wp, cmd, path, NULL, -1, &env, s->tio,
+ &cause) != 0) {
cmdq_error(cmdq, "respawn pane failed: %s", cause);
free(cause);
environ_free(&env);
diff --git a/usr.bin/tmux/cmd-respawn-window.c b/usr.bin/tmux/cmd-respawn-window.c
index 50867f83369..6569052b440 100644
--- a/usr.bin/tmux/cmd-respawn-window.c
+++ b/usr.bin/tmux/cmd-respawn-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-respawn-window.c,v 1.20 2013/10/10 12:29:53 nicm Exp $ */
+/* $OpenBSD: cmd-respawn-window.c,v 1.21 2014/04/17 13:02:59 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -47,8 +47,9 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct window_pane *wp;
struct session *s;
struct environ env;
- const char *cmd;
+ const char *cmd, *path;
char *cause;
+ struct environ_entry *envent;
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
@@ -79,7 +80,17 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
cmd = args->argv[0];
else
cmd = NULL;
- if (window_pane_spawn(wp, cmd, NULL, -1, &env, s->tio, &cause) != 0) {
+
+ path = NULL;
+ if (cmdq->client != NULL && cmdq->client->session == NULL)
+ envent = environ_find(&cmdq->client->environ, "PATH");
+ else
+ envent = environ_find(&s->environ, "PATH");
+ if (envent != NULL)
+ path = envent->value;
+
+ if (window_pane_spawn(wp, cmd, path, NULL, -1, &env, s->tio,
+ &cause) != 0) {
cmdq_error(cmdq, "respawn window failed: %s", cause);
free(cause);
environ_free(&env);
diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c
index 3266f16e26c..8dde150b4f6 100644
--- a/usr.bin/tmux/cmd-split-window.c
+++ b/usr.bin/tmux/cmd-split-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-split-window.c,v 1.48 2013/11/22 20:58:36 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.49 2014/04/17 13:02:59 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -61,7 +61,7 @@ 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, *shell, *template;
+ const char *cmd, *path, *shell, *template;
char *cause, *new_cause, *cp;
u_int hlimit;
int size, percentage, cwd, fd = -1;
@@ -69,6 +69,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct layout_cell *lc;
struct client *c;
struct format_tree *ft;
+ struct environ_entry *envent;
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
@@ -148,8 +149,17 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
goto error;
}
new_wp = window_add_pane(w, hlimit);
+
+ path = NULL;
+ if (cmdq->client != NULL && cmdq->client->session == NULL)
+ envent = environ_find(&cmdq->client->environ, "PATH");
+ else
+ envent = environ_find(&s->environ, "PATH");
+ if (envent != NULL)
+ path = envent->value;
+
if (window_pane_spawn(
- new_wp, cmd, shell, cwd, &env, s->tio, &cause) != 0)
+ new_wp, cmd, path, shell, cwd, &env, s->tio, &cause) != 0)
goto error;
layout_assign_pane(lc, new_wp);
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index ec8996ecf91..c458366996f 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.42 2014/01/22 14:00:08 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.43 2014/04/17 13:02:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -85,8 +85,9 @@ session_find_by_id(u_int id)
/* Create a new session. */
struct session *
-session_create(const char *name, const char *cmd, int cwd, struct environ *env,
- struct termios *tio, int idx, u_int sx, u_int sy, char **cause)
+session_create(const char *name, const char *cmd, const char *path, int cwd,
+ struct environ *env, struct termios *tio, int idx, u_int sx, u_int sy,
+ char **cause)
{
struct session *s;
@@ -132,7 +133,7 @@ session_create(const char *name, const char *cmd, int cwd, struct environ *env,
RB_INSERT(sessions, &sessions, s);
if (cmd != NULL) {
- if (session_new(s, NULL, cmd, cwd, idx, cause) == NULL) {
+ if (session_new(s, NULL, cmd, path, cwd, idx, cause) == NULL) {
session_destroy(s);
return (NULL);
}
@@ -226,8 +227,8 @@ session_previous_session(struct session *s)
/* Create a new window on a session. */
struct winlink *
-session_new(struct session *s, const char *name, const char *cmd, int cwd,
- int idx, char **cause)
+session_new(struct session *s, const char *name, const char *cmd,
+ const char *path, int cwd, int idx, char **cause)
{
struct window *w;
struct winlink *wl;
@@ -250,8 +251,8 @@ session_new(struct session *s, const char *name, const char *cmd, int cwd,
shell = _PATH_BSHELL;
hlimit = options_get_number(&s->options, "history-limit");
- w = window_create(name, cmd, shell, cwd, &env, s->tio, s->sx, s->sy,
- hlimit, cause);
+ w = window_create(name, cmd, path, shell, cwd, &env, s->tio, s->sx,
+ s->sy, hlimit, cause);
if (w == NULL) {
winlink_remove(&s->windows, wl);
environ_free(&env);
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 1641e010c75..84105c71cf5 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.454 2014/04/17 12:43:38 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.455 2014/04/17 13:02:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -2129,9 +2129,9 @@ void winlink_stack_remove(struct winlink_stack *, struct winlink *);
int window_index(struct window *, u_int *);
struct window *window_find_by_id(u_int);
struct window *window_create1(u_int, u_int);
-struct window *window_create(const char *, const char *, const char *, int,
- struct environ *, struct termios *, u_int, u_int, u_int,
- char **);
+struct window *window_create(const char *, const char *, const char *,
+ const char *, int, struct environ *, struct termios *,
+ u_int, u_int, u_int, char **);
void window_destroy(struct window *);
struct window_pane *window_get_active_at(struct window *, u_int, u_int);
void window_set_active_at(struct window *, u_int, u_int);
@@ -2156,8 +2156,8 @@ struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
void window_pane_destroy(struct window_pane *);
void window_pane_timer_start(struct window_pane *);
int window_pane_spawn(struct window_pane *, const char *,
- const char *, int, struct environ *, struct termios *,
- char **);
+ const char *, const char *, int, struct environ *,
+ struct termios *, char **);
void window_pane_resize(struct window_pane *, u_int, u_int);
void window_pane_alternate_on(struct window_pane *,
struct grid_cell *, int);
@@ -2293,7 +2293,7 @@ RB_PROTOTYPE(sessions, session, entry, session_cmp);
int session_alive(struct session *);
struct session *session_find(const char *);
struct session *session_find_by_id(u_int);
-struct session *session_create(const char *, const char *, int,
+struct session *session_create(const char *, const char *, const char *, int,
struct environ *, struct termios *, int, u_int, u_int,
char **);
void session_destroy(struct session *);
@@ -2301,8 +2301,8 @@ int session_check_name(const char *);
void session_update_activity(struct session *);
struct session *session_next_session(struct session *);
struct session *session_previous_session(struct session *);
-struct winlink *session_new(struct session *, const char *, const char *, int,
- int, char **);
+struct winlink *session_new(struct session *, const char *, const char *,
+ const char *, int, int, char **);
struct winlink *session_attach(
struct session *, struct window *, int, char **);
int session_detach(struct session *, struct winlink *);
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 09eb4ae352c..e90d351e465 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.106 2014/04/17 11:38:35 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.107 2014/04/17 13:02:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -308,8 +308,8 @@ window_create1(u_int sx, u_int sy)
}
struct window *
-window_create(const char *name, const char *cmd, const char *shell,
- int cwd, struct environ *env, struct termios *tio,
+window_create(const char *name, const char *cmd, 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)
{
struct window *w;
@@ -319,7 +319,8 @@ window_create(const char *name, const char *cmd, const char *shell,
wp = window_add_pane(w, hlimit);
layout_init(w, wp);
- if (window_pane_spawn(wp, cmd, shell, cwd, env, tio, cause) != 0) {
+ if (window_pane_spawn(wp, cmd, path, shell, cwd, env, tio,
+ cause) != 0) {
window_destroy(w);
return (NULL);
}
@@ -810,8 +811,9 @@ window_pane_destroy(struct window_pane *wp)
}
int
-window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
- int cwd, struct environ *env, struct termios *tio, char **cause)
+window_pane_spawn(struct window_pane *wp, const char *cmd, const char *path,
+ const char *shell, int cwd, struct environ *env, struct termios *tio,
+ char **cause)
{
struct winsize ws;
char *argv0, paneid[16];
@@ -860,6 +862,8 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
closefrom(STDERR_FILENO + 1);
+ if (path != NULL)
+ environ_set(env, "PATH", path);
xsnprintf(paneid, sizeof paneid, "%%%u", wp->id);
environ_set(env, "TMUX_PANE", paneid);
environ_push(env);