Gentoo Archives: gentoo-commits

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