From: Frantisek Sumsal Date: Fri, 14 Apr 2023 10:58:16 +0000 (+0200) Subject: test: allow overriding PID1's environment for test purposes X-Git-Tag: v254-rc1~712^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7faa4e3782cfcfaab2457abbb32b765a2c918ee7;p=thirdparty%2Fsystemd.git test: allow overriding PID1's environment for test purposes --- diff --git a/test/units/generator-utils.sh b/test/units/generator-utils.sh index 8f502d00ccc..035fd55b0d0 100644 --- a/test/units/generator-utils.sh +++ b/test/units/generator-utils.sh @@ -54,8 +54,26 @@ opt_filter_consumed() {( run_and_list() { local generator="${1:?}" local out_dir="${2:?}" + local environ + + # If $PID1_ENVIRON is set temporarily overmount /proc/1/environ with + # a temporary file that contains contents of $PID1_ENVIRON. This is + # necessary in cases where the generator reads the environment through + # getenv_for_pid(1, ...) or similar like getty-generator does. + # + # Note: $PID1_ENVIRON should be a NUL separated list of env assignments + if [[ -n "${PID1_ENVIRON:-}" ]]; then + environ="$(mktemp)" + echo -ne "${PID1_ENVIRON}\0" >"${environ:?}" + mount -v --bind "$environ" /proc/1/environ + fi rm -fr "${out_dir:?}"/* SYSTEMD_LOG_LEVEL="${SYSTEMD_LOG_LEVEL:-debug}" "$generator" "$out_dir" ls -lR "$out_dir" + + if [[ -n "${environ:-}" ]]; then + umount /proc/1/environ + rm -f "$environ" + fi }