portage.process.spawned_pids.append(pid)
return [pid]
- # Set up the command's pipes.
- my_fds = {}
- # To protect from cases where direct assignment could
- # clobber needed fds ({1:2, 2:1}) we first dupe the fds
- # into unused fds.
- for fd in fd_pipes:
- my_fds[fd] = os.dup(fd_pipes[fd])
- # Then assign them to what they should be.
- for fd in my_fds:
- os.dup2(my_fds[fd], fd)
+ portage.process._setup_pipes(fd_pipes)
# Force consistent color output, in case we are capturing fetch
# output through a normal pipe due to unavailability of ptys.
# Quiet killing of subprocesses by SIGPIPE (see bug #309001).
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
- # Set up the command's pipes.
+ _setup_pipes(fd_pipes)
+
+ # Set requested process permissions.
+ if gid:
+ os.setgid(gid)
+ if groups:
+ os.setgroups(groups)
+ if uid:
+ os.setuid(uid)
+ if umask:
+ os.umask(umask)
+ if pre_exec:
+ pre_exec()
+
+ # And switch to the new process.
+ os.execve(binary, myargs, env)
+
+def _setup_pipes(fd_pipes):
+ """Setup pipes for a forked process."""
my_fds = {}
# To protect from cases where direct assignment could
# clobber needed fds ({1:2, 2:1}) we first dupe the fds
except OSError:
pass
- # Set requested process permissions.
- if gid:
- os.setgid(gid)
- if groups:
- os.setgroups(groups)
- if uid:
- os.setuid(uid)
- if umask:
- os.umask(umask)
- if pre_exec:
- pre_exec()
-
- # And switch to the new process.
- os.execve(binary, myargs, env)
-
def find_binary(binary):
"""
Given a binary name, find the binary in PATH