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.
This commit is contained in:
Nicholas Marriott
2009-08-08 21:52:43 +00:00
parent e985629440
commit 6491274f60
19 changed files with 549 additions and 63 deletions

View File

@ -112,8 +112,8 @@ session_find(const char *name)
/* Create a new session. */
struct session *
session_create(const char *name,
const char *cmd, const char *cwd, u_int sx, u_int sy, char **cause)
session_create(const char *name, const char *cmd, const char *cwd,
struct environ *env, u_int sx, u_int sy, char **cause)
{
struct session *s;
u_int i;
@ -128,6 +128,9 @@ session_create(const char *name,
SLIST_INIT(&s->alerts);
paste_init_stack(&s->buffers);
options_init(&s->options, &global_s_options);
environ_init(&s->environ);
if (env != NULL)
environ_copy(env, &s->environ);
s->sx = sx;
s->sy = sy;
@ -171,6 +174,7 @@ session_destroy(struct session *s)
ARRAY_TRUNC(&sessions, 1);
session_alert_cancel(s, NULL);
environ_free(&s->environ);
options_free(&s->options);
paste_free_stack(&s->buffers);
@ -200,15 +204,21 @@ session_new(struct session *s,
const char *name, const char *cmd, const char *cwd, int idx, char **cause)
{
struct window *w;
const char **env;
struct environ env;
u_int hlimit;
env = server_fill_environ(s);
environ_init(&env);
environ_copy(&global_environ, &env);
environ_copy(&s->environ, &env);
server_fill_environ(s, &env);
hlimit = options_get_number(&s->options, "history-limit");
w = window_create(name, cmd, cwd, env, s->sx, s->sy, hlimit, cause);
if (w == NULL)
w = window_create(name, cmd, cwd, &env, s->sx, s->sy, hlimit, cause);
if (w == NULL) {
environ_free(&env);
return (NULL);
}
environ_free(&env);
if (options_get_number(&s->options, "set-remain-on-exit"))
options_set_number(&w->options, "remain-on-exit", 1);