commit: e9810a30bf044d93c0348d46225ad6b2ae1a45df Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Mon Dec 3 07:47:32 2018 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Tue Dec 4 01:15:03 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e9810a30
portage.process.spawn: inherit env by default (bug 672440) Make child processes inherit the current process's environment by default, so that behavior is equivalent to the standard library's subprocess module. Bug: https://bugs.gentoo.org/672440 Reviewed-by: Brian Dolbec <dolsen <AT> gentoo.org> Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> lib/portage/process.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/portage/process.py b/lib/portage/process.py index ed1a49247..ce3e42a8f 100644 --- a/lib/portage/process.py +++ b/lib/portage/process.py @@ -219,7 +219,7 @@ spawned_pids = _dummy_list() def cleanup(): pass -def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False, +def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False, uid=None, gid=None, groups=None, umask=None, cwd=None, logfile=None, path_lookup=True, pre_exec=None, close_fds=(sys.version_info < (3, 4)), unshare_net=False, @@ -230,8 +230,10 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False, @param mycommand: the command to execute @type mycommand: String or List (Popen style list) - @param env: A dict of Key=Value pairs for env variables - @type env: Dictionary + @param env: If env is not None, it must be a mapping that defines the environment + variables for the new process; these are used instead of the default behavior + of inheriting the current process's environment. + @type env: None or Mapping @param opt_name: an optional name for the spawn'd process (defaults to the binary name) @type opt_name: String @param fd_pipes: A dict of mapping for pipes, { '0': stdin, '1': stdout } for example @@ -281,6 +283,8 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False, if isinstance(mycommand, basestring): mycommand = mycommand.split() + env = os.environ if env is None else env + if sys.hexversion < 0x3000000: # Avoid a potential UnicodeEncodeError from os.execve(). env_bytes = {}
