From 0fd50caeed5c22d3019af82bab83b5b08ef24092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Sl=C3=A1vik?= Date: Wed, 12 Jul 2023 16:00:19 +0200 Subject: [PATCH] Change startProgram preexec check to early exit style This is what we do elsewhere --- pyanaconda/core/util.py | 49 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/pyanaconda/core/util.py b/pyanaconda/core/util.py index 42463f8ae9e..56b7206cb7b 100644 --- a/pyanaconda/core/util.py +++ b/pyanaconda/core/util.py @@ -137,30 +137,31 @@ def startProgram(argv, root='/', stdin=None, stdout=subprocess.PIPE, stderr=subp close_fds=True, restore_signals=restore_signals, cwd=root, env=env, **kwargs) - if do_preexec: - # Check for and save a preexec_fn argument - preexec_fn = kwargs.pop("preexec_fn", None) - - def preexec(): - # If a target root was specificed, chroot into it - if target_root and target_root != '/': - os.chroot(target_root) - os.chdir("/") - - # Signal handlers set to SIG_IGN persist across exec. Reset - # these to SIG_DFL if requested. In particular this will include the - # SIGPIPE handler set by python. - if reset_handlers: - for signum in range(1, signal.NSIG): - if signal.getsignal(signum) == signal.SIG_IGN: - signal.signal(signum, signal.SIG_DFL) - - # If the user specified an additional preexec_fn argument, run it - if preexec_fn is not None: - preexec_fn() - - return partsubp(preexec_fn=preexec) - return partsubp() + if not do_preexec: + return partsubp() + + # Check for and save a preexec_fn argument + preexec_fn = kwargs.pop("preexec_fn", None) + + def preexec(): + # If a target root was specificed, chroot into it + if target_root and target_root != '/': + os.chroot(target_root) + os.chdir("/") + + # Signal handlers set to SIG_IGN persist across exec. Reset + # these to SIG_DFL if requested. In particular this will include the + # SIGPIPE handler set by python. + if reset_handlers: + for signum in range(1, signal.NSIG): + if signal.getsignal(signum) == signal.SIG_IGN: + signal.signal(signum, signal.SIG_DFL) + + # If the user specified an additional preexec_fn argument, run it + if preexec_fn is not None: + preexec_fn() + + return partsubp(preexec_fn=preexec) class X11Status: