Enable FD_CLOEXEC for non-blocking pipes.
authorZac Medico <zmedico@gentoo.org>
Fri, 4 Jan 2013 04:16:17 +0000 (20:16 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 4 Jan 2013 04:16:17 +0000 (20:16 -0800)
pym/_emerge/AsynchronousLock.py
pym/_emerge/EbuildMetadataPhase.py
pym/_emerge/FifoIpcDaemon.py
pym/_emerge/PipeReader.py
pym/portage/dbapi/_MergeProcess.py
pym/portage/util/_async/PipeLogger.py
pym/portage/util/_eventloop/EventLoop.py

index 2de1acdcfb3d12b6add461cf245daa6f98efaef5..fd66a945596e4a017e1d1328f1439f3628f56ead 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import dummy_threading
@@ -164,8 +164,17 @@ class _LockProcess(AbstractPollTask):
                self._files = {}
                self._files['pipe_in'] = in_pr
                self._files['pipe_out'] = out_pw
+
+               fcntl_flags = os.O_NONBLOCK
+               try:
+                       fcntl.FD_CLOEXEC
+               except AttributeError:
+                       pass
+               else:
+                       fcntl_flags |= fcntl.FD_CLOEXEC
+
                fcntl.fcntl(in_pr, fcntl.F_SETFL,
-                       fcntl.fcntl(in_pr, fcntl.F_GETFL) | os.O_NONBLOCK)
+                       fcntl.fcntl(in_pr, fcntl.F_GETFL) | fcntl_flags)
                self._reg_id = self.scheduler.io_add_watch(in_pr,
                        self.scheduler.IO_IN, self._output_handler)
                self._registered = True
index 89734e045331b7e9988f30670ba1db336a360439..4806f5c2ddc37801e26f6f632b348860109fbc4e 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.SubProcess import SubProcess
@@ -91,8 +91,17 @@ class EbuildMetadataPhase(SubProcess):
                files = self._files
 
                master_fd, slave_fd = os.pipe()
+
+               fcntl_flags = os.O_NONBLOCK
+               try:
+                       fcntl.FD_CLOEXEC
+               except AttributeError:
+                       pass
+               else:
+                       fcntl_flags |= fcntl.FD_CLOEXEC
+
                fcntl.fcntl(master_fd, fcntl.F_SETFL,
-                       fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
+                       fcntl.fcntl(master_fd, fcntl.F_GETFL) | fcntl_flags)
 
                fd_pipes[self._metadata_fd] = slave_fd
 
index 959c0076958b288366b9d1b22b2956334492c530..113e49da8e1bb8cb098c269189c5e92394e626bf 100644 (file)
@@ -1,6 +1,12 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+try:
+       import fcntl
+except ImportError:
+       #  http://bugs.jython.org/issue1074
+       fcntl = None
+
 from portage import os
 from _emerge.AbstractPollTask import AbstractPollTask
 from portage.cache.mappings import slot_dict_class
@@ -21,6 +27,16 @@ class FifoIpcDaemon(AbstractPollTask):
                self._files.pipe_in = \
                        os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
 
+               if fcntl is not None:
+                       try:
+                               fcntl.FD_CLOEXEC
+                       except AttributeError:
+                               pass
+                       else:
+                               fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFL,
+                                       fcntl.fcntl(self._files.pipe_in,
+                                               fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
+
                self._reg_id = self.scheduler.io_add_watch(
                        self._files.pipe_in,
                        self._registered_events, self._input_handler)
@@ -36,6 +52,17 @@ class FifoIpcDaemon(AbstractPollTask):
                os.close(self._files.pipe_in)
                self._files.pipe_in = \
                        os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
+
+               if fcntl is not None:
+                       try:
+                               fcntl.FD_CLOEXEC
+                       except AttributeError:
+                               pass
+                       else:
+                               fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFL,
+                                       fcntl.fcntl(self._files.pipe_in,
+                                               fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
+
                self._reg_id = self.scheduler.io_add_watch(
                        self._files.pipe_in,
                        self._registered_events, self._input_handler)
index 7209e9e9358a47efd0faaa6eca268aae0292ce6f..bb4e0dc1c9ecdb519fee21e9834e6aba7bc617ef 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from portage import os
@@ -26,9 +26,17 @@ class PipeReader(AbstractPollTask):
                else:
                        output_handler = self._output_handler
 
+               fcntl_flags = os.O_NONBLOCK
+               try:
+                       fcntl.FD_CLOEXEC
+               except AttributeError:
+                       pass
+               else:
+                       fcntl_flags |= fcntl.FD_CLOEXEC
+
                for f in self.input_files.values():
                        fcntl.fcntl(f.fileno(), fcntl.F_SETFL,
-                               fcntl.fcntl(f.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)
+                               fcntl.fcntl(f.fileno(), fcntl.F_GETFL) | fcntl_flags)
                        self._reg_ids.add(self.scheduler.io_add_watch(f.fileno(),
                                self._registered_events, output_handler))
                self._registered = True
index e2534cf9d23e2b8b80d0f3feb0cd35d1e4b4ad2d..1442d56ac3cf7cb6e7d26ca99e4591b3bfcead98 100644 (file)
@@ -114,8 +114,17 @@ class MergeProcess(ForkProcess):
                """
 
                elog_reader_fd, elog_writer_fd = os.pipe()
+
+               fcntl_flags = os.O_NONBLOCK
+               try:
+                       fcntl.FD_CLOEXEC
+               except AttributeError:
+                       pass
+               else:
+                       fcntl_flags |= fcntl.FD_CLOEXEC
+
                fcntl.fcntl(elog_reader_fd, fcntl.F_SETFL,
-                       fcntl.fcntl(elog_reader_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
+                       fcntl.fcntl(elog_reader_fd, fcntl.F_GETFL) | fcntl_flags)
                blockers = None
                if self.blockers is not None:
                        # Query blockers in the main process, since closing
index 0905e47f9dd5e42f819a472dd038f52ae09267b2..376ebfef7693e277e8d9256bfd93d1f76c50d923 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2008-2012 Gentoo Foundation
+# Copyright 2008-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import fcntl
@@ -38,8 +38,16 @@ class PipeLogger(AbstractPollTask):
                                uid=portage.portage_uid, gid=portage.portage_gid,
                                mode=0o660)
 
+               fcntl_flags = os.O_NONBLOCK
+               try:
+                       fcntl.FD_CLOEXEC
+               except AttributeError:
+                       pass
+               else:
+                       fcntl_flags |= fcntl.FD_CLOEXEC
+
                fcntl.fcntl(self.input_fd, fcntl.F_SETFL,
-                       fcntl.fcntl(self.input_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
+                       fcntl.fcntl(self.input_fd, fcntl.F_GETFL) | fcntl_flags)
 
                self._reg_id = self.scheduler.io_add_watch(self.input_fd,
                        self._registered_events, self._output_handler)
index 6c2341bcd28dd943bd7f6b25cb02a0ce28d27464..ad64406c07017f282a668479aa341f54f2892e72 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import errno
@@ -308,9 +308,18 @@ class EventLoop(object):
                if self._use_signal:
                        if self._sigchld_read is None:
                                self._sigchld_read, self._sigchld_write = os.pipe()
+
+                               fcntl_flags = os.O_NONBLOCK
+                               try:
+                                       fcntl.FD_CLOEXEC
+                               except AttributeError:
+                                       pass
+                               else:
+                                       fcntl_flags |= fcntl.FD_CLOEXEC
+
                                fcntl.fcntl(self._sigchld_read, fcntl.F_SETFL,
                                        fcntl.fcntl(self._sigchld_read,
-                                       fcntl.F_GETFL) | os.O_NONBLOCK)
+                                       fcntl.F_GETFL) | fcntl_flags)
 
                        # The IO watch is dynamically registered and unregistered as
                        # needed, since we don't want to consider it as a valid source