From 266cd3d17cdb8d3dacde171ac157c45f9fee3113 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 6 Sep 2013 13:10:04 -0700 Subject: [PATCH] Adjust pty permissions for userpriv. --- pym/portage/package/ebuild/doebuild.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index 311f548a9..01707aeec 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -1488,6 +1488,25 @@ def spawn(mystring, mysettings, debug=False, free=False, droppriv=False, "groups": userpriv_groups, "umask": 0o02 }) + + # Adjust pty ownership so that subprocesses + # can directly access /dev/fd/{1,2}. + stdout_fd = fd_pipes.get(1) + if stdout_fd is not None: + try: + subprocess_tty = _os.ttyname(stdout_fd) + except OSError: + pass + else: + try: + parent_tty = _os.ttyname(sys.__stdout__.fileno()) + except OSError: + parent_tty = None + + if subprocess_tty != parent_tty: + _os.chown(subprocess_tty, + int(portage_uid), int(portage_gid)) + if "userpriv" in features and "userpriv" not in mysettings["PORTAGE_RESTRICT"].split() and secpass >= 2: # Since Python 3.4, getpwuid and getgrgid # require int type (no proxies). -- 2.26.2