Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] portage.process.spawn: inherit env by default (bug 672440)
Date: Mon, 03 Dec 2018 07:57:02
Message-Id: 20181203075523.27407-1-zmedico@gentoo.org
1 Make child processes inherit the current process's environment by
2 default, so that behavior is equivalent to the standard library's
3 subprocess module.
4
5 Bug: https://bugs.gentoo.org/672440
6 Signed-off-by: Zac Medico <zmedico@g.o>
7 ---
8 lib/portage/process.py | 10 +++++++---
9 1 file changed, 7 insertions(+), 3 deletions(-)
10
11 diff --git a/lib/portage/process.py b/lib/portage/process.py
12 index ed1a49247..ce3e42a8f 100644
13 --- a/lib/portage/process.py
14 +++ b/lib/portage/process.py
15 @@ -219,7 +219,7 @@ spawned_pids = _dummy_list()
16 def cleanup():
17 pass
18
19 -def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
20 +def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False,
21 uid=None, gid=None, groups=None, umask=None, cwd=None, logfile=None,
22 path_lookup=True, pre_exec=None,
23 close_fds=(sys.version_info < (3, 4)), unshare_net=False,
24 @@ -230,8 +230,10 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
25
26 @param mycommand: the command to execute
27 @type mycommand: String or List (Popen style list)
28 - @param env: A dict of Key=Value pairs for env variables
29 - @type env: Dictionary
30 + @param env: If env is not None, it must be a mapping that defines the environment
31 + variables for the new process; these are used instead of the default behavior
32 + of inheriting the current process's environment.
33 + @type env: None or Mapping
34 @param opt_name: an optional name for the spawn'd process (defaults to the binary name)
35 @type opt_name: String
36 @param fd_pipes: A dict of mapping for pipes, { '0': stdin, '1': stdout } for example
37 @@ -281,6 +283,8 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
38 if isinstance(mycommand, basestring):
39 mycommand = mycommand.split()
40
41 + env = os.environ if env is None else env
42 +
43 if sys.hexversion < 0x3000000:
44 # Avoid a potential UnicodeEncodeError from os.execve().
45 env_bytes = {}
46 --
47 2.18.1

Replies