self._files['pipe_in'] = in_pr
self._files['pipe_out'] = out_pw
- fcntl_flags = os.O_NONBLOCK
+ 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_flags |= fcntl.FD_CLOEXEC
+ fcntl.fcntl(in_pr, fcntl.F_SETFD,
+ fcntl.fcntl(in_pr, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
- fcntl.fcntl(in_pr, fcntl.F_SETFL,
- 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
master_fd, slave_fd = os.pipe()
- fcntl_flags = os.O_NONBLOCK
+ 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_flags |= fcntl.FD_CLOEXEC
-
- fcntl.fcntl(master_fd, fcntl.F_SETFL,
- fcntl.fcntl(master_fd, fcntl.F_GETFL) | fcntl_flags)
+ 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)
except AttributeError:
pass
else:
- fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFL,
+ fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
fcntl.fcntl(self._files.pipe_in,
- fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
+ fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
self._reg_id = self.scheduler.io_add_watch(
self._files.pipe_in,
except AttributeError:
pass
else:
- fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFL,
+ fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
fcntl.fcntl(self._files.pipe_in,
- fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
+ fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
self._reg_id = self.scheduler.io_add_watch(
self._files.pipe_in,
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():
fd = isinstance(f, int) and f or f.fileno()
fcntl.fcntl(fd, fcntl.F_SETFL,
- fcntl.fcntl(fd, fcntl.F_GETFL) | fcntl_flags)
+ 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)
self._reg_ids.add(self.scheduler.io_add_watch(fd,
self._registered_events, output_handler))
self._registered = True
from portage.util._async.PipeLogger import PipeLogger
# On Darwin, FD_CLOEXEC triggers errno 35 for stdout (bug #456296)
+# TODO: Test this again now that it's been fixed to use
+# F_GETFD/F_SETFD instead of F_GETFL/F_SETFL.
_disable_cloexec_stdout = platform.system() in ("Darwin",)
class SpawnProcess(SubProcess):
pass
else:
try:
- fcntl.fcntl(stdout_fd, fcntl.F_SETFL,
+ fcntl.fcntl(stdout_fd, fcntl.F_SETFD,
fcntl.fcntl(stdout_fd,
- fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
+ fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
except IOError:
# FreeBSD may return "Inappropriate ioctl for device"
- # error here (ENOTTY).
+ # error here (ENOTTY). TODO: Test this again now that
+ # it's been fixed to use F_GETFD/F_SETFD instead of
+ # F_GETFL/F_SETFL.
pass
self._pipe_logger = PipeLogger(background=self.background,
elog_reader_fd, elog_writer_fd = os.pipe()
- fcntl_flags = os.O_NONBLOCK
+ 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_flags |= fcntl.FD_CLOEXEC
+ fcntl.fcntl(elog_reader_fd, fcntl.F_SETFD,
+ fcntl.fcntl(elog_reader_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
- fcntl.fcntl(elog_reader_fd, fcntl.F_SETFL,
- 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
except AttributeError:
pass
else:
- fcntl.fcntl(myfd, fcntl.F_SETFL,
- fcntl.fcntl(myfd, fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
+ fcntl.fcntl(myfd, fcntl.F_SETFD,
+ fcntl.fcntl(myfd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
_open_fds.add(myfd)
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
-
if isinstance(self.input_fd, int):
fd = self.input_fd
else:
fd = self.input_fd.fileno()
fcntl.fcntl(fd, fcntl.F_SETFL,
- fcntl.fcntl(fd, fcntl.F_GETFL) | fcntl_flags)
+ 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)
self._reg_id = self.scheduler.io_add_watch(fd,
self._registered_events, self._output_handler)
except AttributeError:
pass
else:
- fcntl.fcntl(epoll_obj.fileno(), fcntl.F_SETFL,
+ fcntl.fcntl(epoll_obj.fileno(), fcntl.F_SETFD,
fcntl.fcntl(epoll_obj.fileno(),
- fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
+ fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
self._poll_obj = _epoll_adapter(epoll_obj)
self.IO_ERR = select.EPOLLERR
if self._sigchld_read is None:
self._sigchld_read, self._sigchld_write = os.pipe()
- fcntl_flags = os.O_NONBLOCK
+ fcntl.fcntl(self._sigchld_read, fcntl.F_SETFL,
+ fcntl.fcntl(self._sigchld_read,
+ fcntl.F_GETFL) | 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) | fcntl_flags)
+ 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