aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Schmaus <flo@geekplace.eu>2021-04-23 12:56:33 +0200
committerZac Medico <zmedico@gentoo.org>2021-06-13 14:45:33 -0700
commit209be9a8bee13384dd04a4762436b4c2a5e35bc6 (patch)
treead743a216b5ba3d43688b420aaa003486cf846e4
parentPORTAGE_NICENESS: Consider autogroup scheduling (diff)
downloadportage-209be9a8bee13384dd04a4762436b4c2a5e35bc6.tar.gz
portage-209be9a8bee13384dd04a4762436b4c2a5e35bc6.tar.bz2
portage-209be9a8bee13384dd04a4762436b4c2a5e35bc6.zip
pid-ns-init: Carry the autogroup's nice value into the new session
Closes: https://github.com/gentoo/portage/pull/693 Signed-off-by: Florian Schmaus <flo@geekplace.eu> Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--bin/pid-ns-init22
1 files changed, 21 insertions, 1 deletions
diff --git a/bin/pid-ns-init b/bin/pid-ns-init
index e410dd028..c8e82bdb7 100644
--- a/bin/pid-ns-init
+++ b/bin/pid-ns-init
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright 2018-2020 Gentoo Authors
+# Copyright 2018-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import errno
@@ -12,6 +12,7 @@ import subprocess
import sys
import termios
+from pathlib import Path
KILL_SIGNALS = (
signal.SIGINT,
@@ -91,9 +92,28 @@ def main(argv):
'preexec_fn': functools.partial(preexec_fn, uid, gid, groups, umask),
'pass_fds': pass_fds,
}
+
+ # Try to obtain the current autogroup's nice value.
+ autogroup_nice = None
+ autogroup_file = Path("/proc/self/autogroup")
+ try:
+ f = autogroup_file.open("r")
+ except EnvironmentError:
+ pass
+ else:
+ with f:
+ line = f.readline()
+ autogroup_nice = line.split(" ")[2]
+
# Isolate parent process from process group SIGSTOP (bug 675870)
setsid = True
os.setsid()
+
+ if autogroup_nice:
+ # Set the previously obtained autogroup nice value again,
+ # since we created a new session with os.setsid() above.
+ autogroup_file.write_text(autogroup_nice)
+
if sys.stdout.isatty():
try:
fcntl.ioctl(sys.stdout, termios.TIOCSCTTY, 0)