Bug #162404 - Automatically disable logging if sesandbox is enabled and a
authorZac Medico <zmedico@gentoo.org>
Sat, 5 Dec 2009 23:00:55 +0000 (23:00 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 5 Dec 2009 23:00:55 +0000 (23:00 -0000)
pty is not available for some reason (currently they are never available
with python3).

svn path=/main/trunk/; revision=14928

pym/_emerge/EbuildProcess.py
pym/_emerge/SpawnProcess.py
pym/portage/__init__.py

index 86a63282ffaa6c21ffbc8666a82f33cafcd81cfc..a6a0b362ba8dc089450b86967ed3f9e92f4fe4dd 100644 (file)
@@ -24,6 +24,13 @@ class EbuildProcess(SpawnProcess):
                        portage._create_pty_or_pipe(copy_term_size=stdout_pipe)
                return (master_fd, slave_fd)
 
+       def _can_log(self, slave_fd):
+               # With sesandbox, logging works through a pty but not through a
+               # normal pipe. So, disable logging if ptys are broken.
+               # See Bug #162404.
+               return not ('sesandbox' in self.settings.features \
+                       and self.settings.selinux_enabled()) or os.isatty(slave_fd)
+
        def _spawn(self, args, **kwargs):
 
                root_config = self.pkg.root_config
index 1486e6773f8bb4ce1aae1ac9ba4ea8f19c0a0881..67fb17e29693e5caf0f5e7921a0df6abe31f61d5 100644 (file)
@@ -49,7 +49,6 @@ class SpawnProcess(SubProcess):
                        if fd == sys.stderr.fileno():
                                sys.stderr.flush()
 
-               logfile = self.logfile
                self._files = self._files_dict()
                files = self._files
 
@@ -57,6 +56,10 @@ class SpawnProcess(SubProcess):
                fcntl.fcntl(master_fd, fcntl.F_SETFL,
                        fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
 
+               logfile = None
+               if self._can_log(slave_fd):
+                       logfile = self.logfile
+
                null_input = None
                fd_pipes_orig = fd_pipes.copy()
                if self.background:
@@ -125,6 +128,9 @@ class SpawnProcess(SubProcess):
                self.pid = retval[0]
                portage.process.spawned_pids.remove(self.pid)
 
+       def _can_log(self, slave_fd):
+               return True
+
        def _pipe(self, fd_pipes):
                """
                @type fd_pipes: dict
index dde0aeadb087f5e4afb2c0dbf40f92b4b20796f3..053e33b25b5021a84d546e4f98558a1eef9d207d 100644 (file)
@@ -4057,12 +4057,25 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, fakero
                if 1 not in fd_pipes or 2 not in fd_pipes:
                        raise ValueError(fd_pipes)
 
+               got_pty, master_fd, slave_fd = \
+                       _create_pty_or_pipe(copy_term_size=fd_pipes[1])
+
+               if not got_pty and 'sesandbox' in mysettings.features \
+                       and mysettings.selinux_enabled():
+                       # With sesandbox, logging works through a pty but not through a
+                       # normal pipe. So, disable logging if ptys are broken.
+                       # See Bug #162404.
+                       logfile = None
+                       os.close(master_fd)
+                       master_fd = None
+                       os.close(slave_fd)
+                       slave_fd = None
+
+       if logfile:
+
                fd_pipes.setdefault(0, sys.stdin.fileno())
                fd_pipes_orig = fd_pipes.copy()
 
-               got_pty, master_fd, slave_fd = \
-                       _create_pty_or_pipe(copy_term_size=fd_pipes_orig[1])
-
                # We must set non-blocking mode before we close the slave_fd
                # since otherwise the fcntl call can fail on FreeBSD (the child
                # process might have already exited and closed slave_fd so we