summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2013-01-03 15:45:38 -0800
committerZac Medico <zmedico@gentoo.org>2013-01-03 15:45:38 -0800
commit9294e9be09f75acbf0ea4b14e9ac2b17962fe122 (patch)
tree3d36b3ccc1f934bf1a982ca8cc6bbc609704d37c
parentfbc857d820ee83d99521e32a7378e1c24d43edb4 (diff)
downloadportage-9294e9be09f75acbf0ea4b14e9ac2b17962fe122.tar.gz
portage-9294e9be09f75acbf0ea4b14e9ac2b17962fe122.tar.bz2
portage-9294e9be09f75acbf0ea4b14e9ac2b17962fe122.zip
spawn: add close_fds parameter
-rw-r--r--pym/portage/process.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/pym/portage/process.py b/pym/portage/process.py
index 63c315423..4cf1cec60 100644
--- a/pym/portage/process.py
+++ b/pym/portage/process.py
@@ -1,5 +1,5 @@
# portage.py -- core Portage functionality
-# Copyright 1998-2012 Gentoo Foundation
+# Copyright 1998-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
@@ -164,7 +164,7 @@ atexit_register(cleanup)
def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
uid=None, gid=None, groups=None, umask=None, logfile=None,
- path_lookup=True, pre_exec=None):
+ path_lookup=True, pre_exec=None, close_fds=True):
"""
Spawns a given command.
@@ -175,6 +175,7 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
@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
+ (default is {0:stdin, 1:stdout, 2:stderr})
@type fd_pipes: Dictionary
@param returnpid: Return the Process IDs for a successful spawn.
NOTE: This requires the caller clean up all the PIDs, otherwise spawn will clean them.
@@ -193,6 +194,9 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
@type path_lookup: Boolean
@param pre_exec: A function to be called with no arguments just prior to the exec call.
@type pre_exec: callable
+ @param close_fds: If True, then close all file descriptors except those
+ referenced by fd_pipes (default is True).
+ @type close_fds: Boolean
logfile requires stdout and stderr to be assigned to this process (ie not pointed
somewhere else.)
@@ -264,7 +268,7 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
if pid == 0:
try:
_exec(binary, mycommand, opt_name, fd_pipes,
- env, gid, groups, uid, umask, pre_exec)
+ env, gid, groups, uid, umask, pre_exec, close_fds)
except SystemExit:
raise
except Exception as e:
@@ -340,7 +344,7 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
return 0
def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask,
- pre_exec):
+ pre_exec, close_fds):
"""
Execute a given binary with options
@@ -395,7 +399,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask,
# the parent process (see bug #289486).
signal.signal(signal.SIGQUIT, signal.SIG_DFL)
- _setup_pipes(fd_pipes)
+ _setup_pipes(fd_pipes, close_fds=close_fds)
# Set requested process permissions.
if gid: