summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-04-04 19:02:10 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-04-04 19:02:10 +0000
commitff186870cba9f97cf1d60ce552b0eefad930c033 (patch)
tree0612073cd25cebe995c8fd141c154926a85a4d8b /usr.bin/tmux
parentc11891f34e66b20b4a5932d6dc2759ea07aa9fc1 (diff)
Run job commands explicitly in the global enviroment (which can be
modified with setenv -g) rather than with the environment tmux started with.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/environ.c40
-rw-r--r--usr.bin/tmux/job.c5
-rw-r--r--usr.bin/tmux/tmux.18
-rw-r--r--usr.bin/tmux/tmux.h3
-rw-r--r--usr.bin/tmux/window.c30
5 files changed, 56 insertions, 30 deletions
diff --git a/usr.bin/tmux/environ.c b/usr.bin/tmux/environ.c
index 28a9fd833ad..16b7f19a3e1 100644
--- a/usr.bin/tmux/environ.c
+++ b/usr.bin/tmux/environ.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: environ.c,v 1.3 2009/08/09 15:17:50 nicm Exp $ */
+/* $OpenBSD: environ.c,v 1.4 2010/04/04 19:02:09 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -35,12 +35,14 @@ environ_cmp(struct environ_entry *envent1, struct environ_entry *envent2)
return (strcmp(envent1->name, envent2->name));
}
+/* Initialise the environment. */
void
environ_init(struct environ *env)
{
RB_INIT(env);
}
+/* Free an environment. */
void
environ_free(struct environ *env)
{
@@ -56,6 +58,7 @@ environ_free(struct environ *env)
}
}
+/* Copy one environment into another. */
void
environ_copy(struct environ *srcenv, struct environ *dstenv)
{
@@ -65,6 +68,7 @@ environ_copy(struct environ *srcenv, struct environ *dstenv)
environ_set(dstenv, envent->name, envent->value);
}
+/* Find an environment variable. */
struct environ_entry *
environ_find(struct environ *env, const char *name)
{
@@ -74,6 +78,7 @@ environ_find(struct environ *env, const char *name)
return (RB_FIND(environ, env, &envent));
}
+/* Set an environment variable. */
void
environ_set(struct environ *env, const char *name, const char *value)
{
@@ -97,10 +102,11 @@ environ_set(struct environ *env, const char *name, const char *value)
}
}
+/* Set an environment variable from a NAME=VALUE string. */
void
environ_put(struct environ *env, const char *var)
{
- char *name, *value;
+ char *name, *value;
value = strchr(var, '=');
if (value == NULL)
@@ -114,6 +120,7 @@ environ_put(struct environ *env, const char *var)
xfree(name);
}
+/* Unset an environment variable. */
void
environ_unset(struct environ *env, const char *name)
{
@@ -128,6 +135,10 @@ environ_unset(struct environ *env, const char *name)
xfree(envent);
}
+/*
+ * Copy a space-separated list of variables from a destination into a source
+ * environment.
+ */
void
environ_update(const char *vars, struct environ *srcenv, struct environ *dstenv)
{
@@ -143,3 +154,28 @@ environ_update(const char *vars, struct environ *srcenv, struct environ *dstenv)
}
xfree(copyvars);
}
+
+/* Push environment into the real environment - use after fork(). */
+void
+environ_push(struct environ *env)
+{
+ ARRAY_DECL(, char *) varlist;
+ struct environ_entry *envent;
+ char **varp, *var;
+ u_int i;
+
+ ARRAY_INIT(&varlist);
+ for (varp = environ; *varp != NULL; varp++) {
+ var = xstrdup(*varp);
+ var[strcspn(var, "=")] = '\0';
+ ARRAY_ADD(&varlist, var);
+ }
+ for (i = 0; i < ARRAY_LENGTH(&varlist); i++)
+ unsetenv(ARRAY_ITEM(&varlist, i));
+ ARRAY_FREE(&varlist);
+
+ RB_FOREACH(envent, environ, env) {
+ if (envent->value != NULL)
+ setenv(envent->name, envent->value, 1);
+ }
+}
diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c
index 11bd831b37a..fd2174e07f7 100644
--- a/usr.bin/tmux/job.c
+++ b/usr.bin/tmux/job.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: job.c,v 1.15 2010/02/24 19:13:38 nicm Exp $ */
+/* $OpenBSD: job.c,v 1.16 2010/04/04 19:02:09 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -150,7 +150,8 @@ job_run(struct job *job)
return (-1);
case 0: /* child */
server_signal_clear();
- /* XXX environ? */
+
+ environ_push(&global_environ);
if (dup2(out[1], STDOUT_FILENO) == -1)
fatal("dup2 failed");
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 383144378cd..61bbd82dc42 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.160 2010/03/27 11:46:58 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.161 2010/04/04 19:02:09 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: March 27 2010 $
+.Dd $Mdocdate: April 4 2010 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1745,6 +1745,10 @@ the
.Ic status-interval
option: if the status line is redrawn in the meantime, the previous result is
used.
+Shell commands are executed with the
+.Nm
+global environment set (see the
+.Sx ENVIRONMENT section).
.Pp
#[attributes] allows a comma-separated list of attributes to be specified,
these may be
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 4b682c0de25..c2da7c63f3b 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.214 2010/04/04 18:48:37 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.215 2010/04/04 19:02:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1330,6 +1330,7 @@ void environ_set(struct environ *, const char *, const char *);
void environ_put(struct environ *, const char *);
void environ_unset(struct environ *, const char *);
void environ_update(const char *, struct environ *, struct environ *);
+void environ_push(struct environ *);
/* tty.c */
void tty_raw(struct tty *, const char *);
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 1987d6e75eb..47f705a43a0 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.46 2010/04/04 18:48:37 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.47 2010/04/04 19:02:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -480,14 +480,11 @@ int
window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
const char *cwd, struct environ *env, struct termios *tio, char **cause)
{
- struct winsize ws;
- int mode;
- char *argv0, **varp, *var;
- ARRAY_DECL(, char *) varlist;
- struct environ_entry *envent;
- const char *ptr;
- struct termios tio2;
- u_int i;
+ struct winsize ws;
+ int mode;
+ char *argv0;
+ const char *ptr;
+ struct termios tio2;
if (wp->fd != -1) {
close(wp->fd);
@@ -530,20 +527,7 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
if (tcsetattr(STDIN_FILENO, TCSANOW, &tio2) != 0)
fatal("tcgetattr failed");
- ARRAY_INIT(&varlist);
- for (varp = environ; *varp != NULL; varp++) {
- var = xstrdup(*varp);
- var[strcspn(var, "=")] = '\0';
- ARRAY_ADD(&varlist, var);
- }
- for (i = 0; i < ARRAY_LENGTH(&varlist); i++) {
- var = ARRAY_ITEM(&varlist, i);
- unsetenv(var);
- }
- RB_FOREACH(envent, environ, env) {
- if (envent->value != NULL)
- setenv(envent->name, envent->value, 1);
- }
+ environ_push(env);
server_signal_clear();
log_close();