From 82d149c85d131916ba6c78c781b9ff2d425c594a Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Sat, 5 Dec 2020 14:19:39 +0100 Subject: [PATCH] Make pmb.helpers.run.root support non-timeout output modes (MR 1996) Before this commit, pmb.helpers.run_core.sanity_checks would raise a runtime error when pmb.helpers.run.root was called with an output mode that did not support timeouts (like background). --- pmb/config/__init__.py | 7 +++++++ pmb/helpers/run.py | 6 +++++- pmb/helpers/run_core.py | 5 +++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 932fbf79..b5dd188b 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -98,6 +98,13 @@ defaults = { "extra_space": "0" } + +# pmbootstrap will kill programs which do not output anything for several +# minutes and have one of the following output types. See +# pmb.helpers.run_core.core() for more information. +run_outputs_with_timeout = ["log", "stdout"] + + # # CHROOT # diff --git a/pmb/helpers/run.py b/pmb/helpers/run.py index 5cdeb781..71db19b1 100644 --- a/pmb/helpers/run.py +++ b/pmb/helpers/run.py @@ -73,5 +73,9 @@ def root(args, cmd, working_dir=None, output="log", output_return=False, if env: cmd = ["sh", "-c", flat_cmd(cmd, env=env)] cmd = ["sudo"] + cmd + + # pmbootstrap shall use 'sudo kill' to get rid of timed out programs + kill_as_root = output in pmb.config.run_outputs_with_timeout or None + return user(args, cmd, working_dir, output, output_return, check, env, - True) + kill_as_root) diff --git a/pmb/helpers/run_core.py b/pmb/helpers/run_core.py index 48e20d46..290f5d01 100644 --- a/pmb/helpers/run_core.py +++ b/pmb/helpers/run_core.py @@ -33,7 +33,7 @@ def sanity_checks(output="log", output_return=False, check=None, if output_return and output in ["tui", "background"]: raise RuntimeError("Can't use output_return with output: " + output) - if kill_as_root and output in ["interactive", "tui", "background"]: + if kill_as_root and output not in pmb.config.run_outputs_with_timeout: raise RuntimeError("Can't use kill_as_root with output: " + output) @@ -270,7 +270,8 @@ def core(args, log_message, cmd, working_dir=None, output="log", if not args.details_to_stdout and output in ["stdout", "interactive"]: output_to_stdout = True - output_timeout = output in ["log", "stdout"] and not disable_timeout + output_timeout = output in pmb.config.run_outputs_with_timeout \ + and not disable_timeout (code, output_after_run) = foreground_pipe(args, cmd, working_dir, output_to_stdout, output_return,