]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use setpgid if available 1922/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 25 Sep 2023 11:00:52 +0000 (13:00 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 25 Sep 2023 12:01:17 +0000 (14:01 +0200)
The next release of util-linux will include setpgid which has a
--foreground option that does exactly the same as our foreground()
function. This new utility allows us to make the processes executed
by bubblewrap the foreground process, which makes sure that SIGINT
isn't intercepted by bwrap.

mkosi/run.py

index d4b5595fc7ebcdfd7cafb70dc322d91b8147e23e..71d6fbcdab955b29eeab19074cd0d88363e69d1c 100644 (file)
@@ -346,6 +346,9 @@ def bwrap(
             "sh", "-c", "chmod 1777 /dev/shm && exec $0 \"$@\"",
         ]
 
+        if setpgid := find_binary("setpgid"):
+            cmdline += [setpgid, "--foreground"]
+
         try:
             result = run([*cmdline, *cmd], env=env, log=False, stdin=stdin, stdout=stdout, input=input)
         except subprocess.CalledProcessError as e:
@@ -394,6 +397,9 @@ def apivfs_cmd(root: Path) -> list[PathString]:
         "--unsetenv", "TMPDIR",
     ]
 
+    if setpgid := find_binary("setpgid"):
+        cmdline += [setpgid, "--foreground"]
+
     if (root / "etc/machine-id").exists():
         # Make sure /etc/machine-id is not overwritten by any package manager post install scripts.
         cmdline += ["--ro-bind", root / "etc/machine-id", root / "etc/machine-id"]
@@ -435,6 +441,9 @@ def chroot_cmd(root: Path, *, options: Sequence[PathString] = ()) -> list[PathSt
         *options,
     ]
 
+    if setpgid := find_binary("setpgid", root):
+        cmdline += [setpgid, "--foreground"]
+
     return apivfs_cmd(root) + cmdline