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