mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-03 16:46:18 +00:00 
			
		
		
		
	Sync OpenBSD patchset 231:
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 session 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:
		
							
								
								
									
										24
									
								
								session.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								session.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: session.c,v 1.59 2009-07-08 18:03:03 nicm Exp $ */
 | 
			
		||||
/* $Id: session.c,v 1.60 2009-08-09 17:48:55 tcunha Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user