]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add foreground argument to run()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 28 Mar 2024 10:56:35 +0000 (11:56 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 28 Mar 2024 11:44:51 +0000 (12:44 +0100)
mkosi/run.py

index 548ca52e2c01c74db86f831a3eda4804f1d52696..d8171db3d251e1f8ba094e0a2f94c9312a890c66 100644 (file)
@@ -145,6 +145,7 @@ def run(
     log: bool = True,
     preexec_fn: Optional[Callable[[], None]] = None,
     sandbox: Sequence[PathString] = (),
+    foreground: bool = True,
 ) -> CompletedProcess:
     sandbox = [os.fspath(x) for x in sandbox]
     cmdline = [os.fspath(x) for x in cmdline]
@@ -180,11 +181,13 @@ def run(
         stdin = subprocess.DEVNULL
 
     def preexec() -> None:
-        make_foreground_process()
+        if foreground:
+            make_foreground_process()
         if preexec_fn:
             preexec_fn()
 
     if (
+        foreground and
         sandbox and
         subprocess.run(sandbox + ["sh", "-c", "command -v setpgid"], stdout=subprocess.DEVNULL).returncode == 0
     ):
@@ -232,7 +235,8 @@ def run(
         e.cmd = cmdline
         raise
     finally:
-        make_foreground_process(new_process_group=False)
+        if foreground:
+            make_foreground_process(new_process_group=False)
 
 
 @contextlib.contextmanager