From cd0eec80a70e5c5de2c39be5e767a4ce27083372 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Mon, 2 Sep 2013 15:56:29 +0200 Subject: [PATCH] =?utf8?q?Disable=20calls=20to=20fcntl.fcntl(=E2=80=A6,=20?= =?utf8?q?fcntl.F=5FSETFD,=20=E2=80=A6=20|=20fcntl.FD=5FCLOEXEC)=20with=20?= =?utf8?q?Python=20>=3D3.4,=20since=20FD=5FCLOEXEC=20is=20enabled=20by=20d?= =?utf8?q?efault=20in=20Python=20>=3D3.4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- pym/_emerge/AsynchronousLock.py | 16 +++++++++------- pym/_emerge/EbuildMetadataPhase.py | 16 +++++++++------- pym/_emerge/FifoIpcDaemon.py | 8 ++++++-- pym/_emerge/PipeReader.py | 22 ++++++++++++++-------- pym/_emerge/SpawnProcess.py | 3 ++- pym/portage/dbapi/_MergeProcess.py | 16 +++++++++------- pym/portage/locks.py | 16 +++++++++------- pym/portage/util/_async/PipeLogger.py | 17 ++++++++++------- pym/portage/util/_eventloop/EventLoop.py | 22 +++++++++++++--------- 9 files changed, 81 insertions(+), 55 deletions(-) diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py index cfe98b09f..c0b9b26dc 100644 --- a/pym/_emerge/AsynchronousLock.py +++ b/pym/_emerge/AsynchronousLock.py @@ -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) diff --git a/pym/_emerge/EbuildMetadataPhase.py b/pym/_emerge/EbuildMetadataPhase.py index 7882b6369..bbb1ca9dc 100644 --- a/pym/_emerge/EbuildMetadataPhase.py +++ b/pym/_emerge/EbuildMetadataPhase.py @@ -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) diff --git a/pym/_emerge/FifoIpcDaemon.py b/pym/_emerge/FifoIpcDaemon.py index 662aec11c..7468de5e2 100644 --- a/pym/_emerge/FifoIpcDaemon.py +++ b/pym/_emerge/FifoIpcDaemon.py @@ -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: diff --git a/pym/_emerge/PipeReader.py b/pym/_emerge/PipeReader.py index c7eef1d79..a8392c329 100644 --- a/pym/_emerge/PipeReader.py +++ b/pym/_emerge/PipeReader.py @@ -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 diff --git a/pym/_emerge/SpawnProcess.py b/pym/_emerge/SpawnProcess.py index 2c2e1a982..c7872cab0 100644 --- a/pym/_emerge/SpawnProcess.py +++ b/pym/_emerge/SpawnProcess.py @@ -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: diff --git a/pym/portage/dbapi/_MergeProcess.py b/pym/portage/dbapi/_MergeProcess.py index d7280f082..956dbb9e6 100644 --- a/pym/portage/dbapi/_MergeProcess.py +++ b/pym/portage/dbapi/_MergeProcess.py @@ -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: diff --git a/pym/portage/locks.py b/pym/portage/locks.py index 4f356c9c1..8571d8c9a 100644 --- a/pym/portage/locks.py +++ b/pym/portage/locks.py @@ -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) diff --git a/pym/portage/util/_async/PipeLogger.py b/pym/portage/util/_async/PipeLogger.py index 06d820097..aa605d94d 100644 --- a/pym/portage/util/_async/PipeLogger.py +++ b/pym/portage/util/_async/PipeLogger.py @@ -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) diff --git a/pym/portage/util/_eventloop/EventLoop.py b/pym/portage/util/_eventloop/EventLoop.py index 46a1f09f9..9ffcc74d9 100644 --- a/pym/portage/util/_eventloop/EventLoop.py +++ b/pym/portage/util/_eventloop/EventLoop.py @@ -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 -- 2.26.2