diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-08-08 21:52:44 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-08-08 21:52:44 +0000 |
commit | e25abe44e01289aa01c6c4f199ce053d873f56db (patch) | |
tree | a52f7db2acdacf6382b139452ee240ba4e506af9 /usr.bin/tmux/window.c | |
parent | afc7a7f90fe800edd4702c36311f0362cff98bb9 (diff) |
Infrastructure and commands to manage the environment for processes started
within tmux.
There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.
New commands set-environment and show-environment manipulate or display the
environments.
A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.
Diffstat (limited to 'usr.bin/tmux/window.c')
-rw-r--r-- | usr.bin/tmux/window.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index df914543055..6fc13cec4db 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.17 2009/07/28 06:48:44 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.18 2009/08/08 21:52:43 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -254,7 +254,7 @@ window_create1(u_int sx, u_int sy) struct window * window_create(const char *name, const char *cmd, const char *cwd, - const char **envp, u_int sx, u_int sy, u_int hlimit, char **cause) + struct environ *env, u_int sx, u_int sy, u_int hlimit, char **cause) { struct window *w; struct window_pane *wp; @@ -262,7 +262,7 @@ window_create(const char *name, const char *cmd, const char *cwd, w = window_create1(sx, sy); wp = window_add_pane(w, hlimit); layout_init(w); - if (window_pane_spawn(wp, cmd, cwd, envp, cause) != 0) { + if (window_pane_spawn(wp, cmd, cwd, env, cause) != 0) { window_destroy(w); return (NULL); } @@ -456,13 +456,16 @@ window_pane_destroy(struct window_pane *wp) int window_pane_spawn(struct window_pane *wp, - const char *cmd, const char *cwd, const char **envp, char **cause) + const char *cmd, const char *cwd, struct environ *env, char **cause) { - struct winsize ws; - int mode; - const char **envq, *ptr; - char *argv0; - struct timeval tv; + struct winsize ws; + int mode; + char *argv0, **varp, *var; + ARRAY_DECL(, char *) varlist; + struct environ_entry *envent; + const char *ptr; + struct timeval tv; + u_int i; if (wp->fd != -1) close(wp->fd); @@ -495,10 +498,22 @@ window_pane_spawn(struct window_pane *wp, case 0: if (chdir(wp->cwd) != 0) chdir("/"); - for (envq = envp; *envq != NULL; envq++) { - if (putenv(xstrdup(*envq)) != 0) - fatal("putenv 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); + } + sigreset(); log_close(); |