commit:     b2a5f03abc0c172b6189226e6f9a7491a002cf51
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu May 17 18:38:27 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu May 17 18:38:27 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=b2a5f03a

MergeProcess,spawn: unregister SIGCHLD and wakeup_fd (bug 655656)

In order to prevent forked processes from invoking the parent process's
SIGCHLD handler and writing to wakeup_fd (triggering BlockingIOError),
unregister the SIGCHLD and wakeup_fd.

Bug: https://bugs.gentoo.org/655656
Reported-by: Helmut Jarausch <jarausch <AT> igpm.rwth-aachen.de>

 pym/portage/dbapi/_MergeProcess.py | 10 ++++++++++
 pym/portage/process.py             | 10 ++++++++++
 2 files changed, 20 insertions(+)

diff --git a/pym/portage/dbapi/_MergeProcess.py 
b/pym/portage/dbapi/_MergeProcess.py
index fefdf8635..371550079 100644
--- a/pym/portage/dbapi/_MergeProcess.py
+++ b/pym/portage/dbapi/_MergeProcess.py
@@ -178,6 +178,16 @@ class MergeProcess(ForkProcess):
                        signal.signal(signal.SIGINT, signal.SIG_DFL)
                        signal.signal(signal.SIGTERM, signal.SIG_DFL)
 
+                       # Unregister SIGCHLD handler and wakeup_fd for the 
parent
+                       # process's event loop (bug 655656).
+                       signal.signal(signal.SIGCHLD, signal.SIG_DFL)
+                       try:
+                               wakeup_fd = signal.set_wakeup_fd(-1)
+                               if wakeup_fd > 0:
+                                       os.close(wakeup_fd)
+                       except (ValueError, OSError):
+                               pass
+
                        portage.locks._close_fds()
                        # We don't exec, so use close_fds=False
                        # (see _setup_pipes docstring).

diff --git a/pym/portage/process.py b/pym/portage/process.py
index 2af783e22..fd326731a 100644
--- a/pym/portage/process.py
+++ b/pym/portage/process.py
@@ -472,6 +472,16 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, 
groups, uid, umask,
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        signal.signal(signal.SIGTERM, signal.SIG_DFL)
 
+       # Unregister SIGCHLD handler and wakeup_fd for the parent
+       # process's event loop (bug 655656).
+       signal.signal(signal.SIGCHLD, signal.SIG_DFL)
+       try:
+               wakeup_fd = signal.set_wakeup_fd(-1)
+               if wakeup_fd > 0:
+                       os.close(wakeup_fd)
+       except (ValueError, OSError):
+               pass
+
        # Quiet killing of subprocesses by SIGPIPE (see bug #309001).
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)
 

Reply via email to