-/* $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>
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");
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");
/* 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);
-/* $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>
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);
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');
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)
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);
-/* $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>
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);
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);
-/* $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>
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);
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);
-/* $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>
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;
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);
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);
-/* $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>
/* 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;
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);
}
/* 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;
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);
-/* $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>
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);
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);
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 *);
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 *);
-/* $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>
}
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;
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);
}
}
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];
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);