From 3abffc459ff6faeff483abdc53f3a70d6042a18c Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 20 Dec 2023 14:52:24 +0100 Subject: [PATCH] Improve and document the environment variable pass-through. --- src/mailman/bin/master.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/mailman/bin/master.py b/src/mailman/bin/master.py index 5a4816d3e..15d10b0f4 100644 --- a/src/mailman/bin/master.py +++ b/src/mailman/bin/master.py @@ -43,7 +43,10 @@ SECONDS_IN_A_DAY = 86400 SUBPROC_START_WAIT = timedelta(seconds=20) # Environment variables to forward into subprocesses. -PRESERVE_ENVS = ( +# +# This is used by the test framework, but also to make sure spawned +# Python interpreters behave the same way as ours. +PRESERVE_ENVS = { 'COVERAGE_PROCESS_START', 'LANG', 'LANGUAGE', @@ -64,7 +67,7 @@ PRESERVE_ENVS = ( 'MAILMAN_EXTRA_TESTING_CFG', 'PYTHONPATH', 'PYTHONHOME', - ) + } @public @@ -349,10 +352,15 @@ class Loop: return pid # Child. # + # Preserve some environment variables. + env = {k: v for k, v in os.environ.items() # pragma: nocover + if k in PRESERVE_ENVS} + # Set the environment variable which tells the runner that it's # running under bin/master control. This subtly changes the error # behavior of bin/runner. - env = {'MAILMAN_UNDER_MASTER_CONTROL': '1'} + env['MAILMAN_UNDER_MASTER_CONTROL'] = '1' # pragma: nocover + # Craft the command line arguments for the exec() call. rswitch = '--runner=' + spec # Always pass the explicit path to the configuration file to the @@ -372,11 +380,6 @@ class Loop: var_dir = os.environ.get('MAILMAN_VAR_DIR') if var_dir is not None: env['MAILMAN_VAR_DIR'] = var_dir - # For the testing framework, if these environment variables are set, - # pass them on to the subprocess. - for envvar in PRESERVE_ENVS: - if envvar in os.environ: - env[envvar] = os.environ[envvar] args.append(env) os.execle(*args) # We should never get here. -- 2.11.4.GIT