Disable calls to fcntl.fcntl(…, fcntl.F_SETFD, … | fcntl.FD_CLOEXEC) with Python...
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Mon, 2 Sep 2013 13:56:29 +0000 (15:56 +0200)
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Mon, 2 Sep 2013 13:56:29 +0000 (15:56 +0200)
since FD_CLOEXEC is enabled by default in Python >=3.4.

pym/_emerge/AsynchronousLock.py
pym/_emerge/EbuildMetadataPhase.py
pym/_emerge/FifoIpcDaemon.py
pym/_emerge/PipeReader.py
pym/_emerge/SpawnProcess.py
pym/portage/dbapi/_MergeProcess.py
pym/portage/locks.py
pym/portage/util/_async/PipeLogger.py
pym/portage/util/_eventloop/EventLoop.py

index cfe98b09f55c77f5658412f08706c686855f299f..c0b9b26dc6424b6707aee434162917d3529533fd 100644 (file)
@@ -168,13 +168,15 @@ class _LockProcess(AbstractPollTask):
                fcntl.fcntl(in_pr, fcntl.F_SETFL,
                        fcntl.fcntl(in_pr, fcntl.F_GETFL) | os.O_NONBLOCK)
 
-               try:
-                       fcntl.FD_CLOEXEC
-               except AttributeError:
-                       pass
-               else:
-                       fcntl.fcntl(in_pr, fcntl.F_SETFD,
-                               fcntl.fcntl(in_pr, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
+               # FD_CLOEXEC is enabled by default in Python >=3.4.
+               if sys.hexversion < 0x3040000:
+                       try:
+                               fcntl.FD_CLOEXEC
+                       except AttributeError:
+                               pass
+                       else:
+                               fcntl.fcntl(in_pr, fcntl.F_SETFD,
+                                       fcntl.fcntl(in_pr, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
 
                self._reg_id = self.scheduler.io_add_watch(in_pr,
                        self.scheduler.IO_IN, self._output_handler)
index 7882b6369191777290ea028cd4624c46f10c449f..bbb1ca9dcbcf8d469eb22010ace7791deca51aff 100644 (file)
@@ -94,13 +94,15 @@ class EbuildMetadataPhase(SubProcess):
                fcntl.fcntl(master_fd, fcntl.F_SETFL,
                        fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
 
-               try:
-                       fcntl.FD_CLOEXEC
-               except AttributeError:
-                       pass
-               else:
-                       fcntl.fcntl(master_fd, fcntl.F_SETFD,
-                               fcntl.fcntl(master_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
+               # FD_CLOEXEC is enabled by default in Python >=3.4.
+               if sys.hexversion < 0x3040000:
+                       try:
+                               fcntl.FD_CLOEXEC
+                       except AttributeError:
+                               pass
+                       else:
+                               fcntl.fcntl(master_fd, fcntl.F_SETFD,
+                                       fcntl.fcntl(master_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
 
                fd_pipes[slave_fd] = slave_fd
                settings["PORTAGE_PIPE_FD"] = str(slave_fd)
index 662aec11c8ab0ccc8eb930e793675e9445b0746e..7468de5e2d3edea2bd20d36246d3f46a9726f40e 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import sys
+
 try:
        import fcntl
 except ImportError:
@@ -27,7 +29,8 @@ class FifoIpcDaemon(AbstractPollTask):
                self._files.pipe_in = \
                        os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
 
-               if fcntl is not None:
+               # FD_CLOEXEC is enabled by default in Python >=3.4.
+               if sys.hexversion < 0x3040000 and fcntl is not None:
                        try:
                                fcntl.FD_CLOEXEC
                        except AttributeError:
@@ -53,7 +56,8 @@ class FifoIpcDaemon(AbstractPollTask):
                self._files.pipe_in = \
                        os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
 
-               if fcntl is not None:
+               # FD_CLOEXEC is enabled by default in Python >=3.4.
+               if sys.hexversion < 0x3040000 and fcntl is not None:
                        try:
                                fcntl.FD_CLOEXEC
                        except AttributeError:
index c7eef1d79b4b5c38c5303e343e0612997661d9d2..a8392c329dd719672fd73a249650413ecbe3c76f 100644 (file)
@@ -1,9 +1,11 @@
 # Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import fcntl
+import sys
+
 from portage import os
 from _emerge.AbstractPollTask import AbstractPollTask
-import fcntl
 
 class PipeReader(AbstractPollTask):
 
@@ -30,13 +32,17 @@ class PipeReader(AbstractPollTask):
                        fd = isinstance(f, int) and f or f.fileno()
                        fcntl.fcntl(fd, fcntl.F_SETFL,
                                fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
-                       try:
-                               fcntl.FD_CLOEXEC
-                       except AttributeError:
-                               pass
-                       else:
-                               fcntl.fcntl(fd, fcntl.F_SETFD,
-                                       fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
+
+                       # FD_CLOEXEC is enabled by default in Python >=3.4.
+                       if sys.hexversion < 0x3040000:
+                               try:
+                                       fcntl.FD_CLOEXEC
+                               except AttributeError:
+                                       pass
+                               else:
+                                       fcntl.fcntl(fd, fcntl.F_SETFD,
+                                               fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
+
                        self._reg_ids.add(self.scheduler.io_add_watch(fd,
                                self._registered_events, output_handler))
                self._registered = True
index 2c2e1a9826d46cd738773f863acfdc7fb753186c..c7872cab07a70f71d66161417436fc80292a2734 100644 (file)
@@ -125,7 +125,8 @@ class SpawnProcess(SubProcess):
                stdout_fd = None
                if can_log and not self.background:
                        stdout_fd = os.dup(fd_pipes_orig[1])
-                       if fcntl is not None and not _disable_cloexec_stdout:
+                       # FD_CLOEXEC is enabled by default in Python >=3.4.
+                       if sys.hexversion < 0x3040000 and fcntl is not None and not _disable_cloexec_stdout:
                                try:
                                        fcntl.FD_CLOEXEC
                                except AttributeError:
index d7280f082e85bf202619f96dbbf904183f446df1..956dbb9e6ec5fb78146bcde486812fee047da9ab 100644 (file)
@@ -120,13 +120,15 @@ class MergeProcess(ForkProcess):
                fcntl.fcntl(elog_reader_fd, fcntl.F_SETFL,
                        fcntl.fcntl(elog_reader_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
 
-               try:
-                       fcntl.FD_CLOEXEC
-               except AttributeError:
-                       pass
-               else:
-                       fcntl.fcntl(elog_reader_fd, fcntl.F_SETFD,
-                               fcntl.fcntl(elog_reader_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
+               # FD_CLOEXEC is enabled by default in Python >=3.4.
+               if sys.hexversion < 0x3040000:
+                       try:
+                               fcntl.FD_CLOEXEC
+                       except AttributeError:
+                               pass
+                       else:
+                               fcntl.fcntl(elog_reader_fd, fcntl.F_SETFD,
+                                       fcntl.fcntl(elog_reader_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
 
                blockers = None
                if self.blockers is not None:
index 4f356c9c1b948fa2ccfb8812ad0d347a4dbc0d3a..8571d8c9acc6328c383ec7cb01d31e49b3baaa49 100644 (file)
@@ -234,13 +234,15 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0,
 
        if myfd != HARDLINK_FD:
 
-               try:
-                       fcntl.FD_CLOEXEC
-               except AttributeError:
-                       pass
-               else:
-                       fcntl.fcntl(myfd, fcntl.F_SETFD,
-                               fcntl.fcntl(myfd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
+               # FD_CLOEXEC is enabled by default in Python >=3.4.
+               if sys.hexversion < 0x3040000:
+                       try:
+                               fcntl.FD_CLOEXEC
+                       except AttributeError:
+                               pass
+                       else:
+                               fcntl.fcntl(myfd, fcntl.F_SETFD,
+                                       fcntl.fcntl(myfd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
 
                _open_fds.add(myfd)
 
index 06d820097509f2368c427728224290faa28f2302..aa605d94d4f2dd53bd875cb7d74f7a8425398159 100644 (file)
@@ -4,6 +4,7 @@
 import fcntl
 import errno
 import gzip
+import sys
 
 import portage
 from portage import os, _encodings, _unicode_encode
@@ -46,13 +47,15 @@ class PipeLogger(AbstractPollTask):
                fcntl.fcntl(fd, fcntl.F_SETFL,
                        fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
 
-               try:
-                       fcntl.FD_CLOEXEC
-               except AttributeError:
-                       pass
-               else:
-                       fcntl.fcntl(fd, fcntl.F_SETFD,
-                               fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
+               # FD_CLOEXEC is enabled by default in Python >=3.4.
+               if sys.hexversion < 0x3040000:
+                       try:
+                               fcntl.FD_CLOEXEC
+                       except AttributeError:
+                               pass
+                       else:
+                               fcntl.fcntl(fd, fcntl.F_SETFD,
+                                       fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
 
                self._reg_id = self.scheduler.io_add_watch(fd,
                        self._registered_events, self._output_handler)
index 46a1f09f902610ec2a052729046449b1adc60f4c..9ffcc74d986ec20dffafa24745ae01ebf0d1c178 100644 (file)
@@ -6,6 +6,7 @@ import logging
 import os
 import select
 import signal
+import sys
 import time
 
 try:
@@ -85,7 +86,8 @@ class EventLoop(object):
                                pass
                        else:
 
-                               if fcntl is not None:
+                               # FD_CLOEXEC is enabled by default in Python >=3.4.
+                               if sys.hexversion < 0x3040000 and fcntl is not None:
                                        try:
                                                fcntl.FD_CLOEXEC
                                        except AttributeError:
@@ -319,14 +321,16 @@ class EventLoop(object):
                                        fcntl.fcntl(self._sigchld_read,
                                        fcntl.F_GETFL) | os.O_NONBLOCK)
 
-                               try:
-                                       fcntl.FD_CLOEXEC
-                               except AttributeError:
-                                       pass
-                               else:
-                                       fcntl.fcntl(self._sigchld_read, fcntl.F_SETFD,
-                                               fcntl.fcntl(self._sigchld_read,
-                                               fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
+                               # FD_CLOEXEC is enabled by default in Python >=3.4.
+                               if sys.hexversion < 0x3040000:
+                                       try:
+                                               fcntl.FD_CLOEXEC
+                                       except AttributeError:
+                                               pass
+                                       else:
+                                               fcntl.fcntl(self._sigchld_read, fcntl.F_SETFD,
+                                                       fcntl.fcntl(self._sigchld_read,
+                                                       fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
 
                        # The IO watch is dynamically registered and unregistered as
                        # needed, since we don't want to consider it as a valid source