_setup_pipes: fix for Python 3.1 to 3.3
authorZac Medico <zmedico@gentoo.org>
Mon, 2 Sep 2013 00:55:21 +0000 (17:55 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 2 Sep 2013 00:55:21 +0000 (17:55 -0700)
This fixes a case where /dev/null stdin fails to inherit since commit
bd2128b7a750a68470f857162784e55b8ac39de2.

pym/portage/process.py

index 2a2fcac7713e3f95a64dcf630c341b78ba21c7a1..9ae7a55ff91f67f7e1b87b066ba4159f13ee17c2 100644 (file)
@@ -583,9 +583,14 @@ def _setup_pipes(fd_pipes, close_fds=True, inheritable=None):
 
                        if oldfd != newfd:
                                os.dup2(oldfd, newfd)
-                               if old_fdflags is None:
-                                       old_fdflags = fcntl.fcntl(oldfd, fcntl.F_GETFD)
-                               fcntl.fcntl(newfd, fcntl.F_SETFD, old_fdflags)
+                               if _set_inheritable is not None:
+                                       # Don't do this unless _set_inheritable is available,
+                                       # since it's used below to ensure correct state, and
+                                       # otherwise /dev/null stdin fails to inherit (at least
+                                       # with Python versions from 3.1 to 3.3).
+                                       if old_fdflags is None:
+                                               old_fdflags = fcntl.fcntl(oldfd, fcntl.F_GETFD)
+                                       fcntl.fcntl(newfd, fcntl.F_SETFD, old_fdflags)
 
                        if _set_inheritable is not None: