From 452f91d8469882f623c3b2c637ce85037ec73621 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 15 May 2024 20:54:33 +0200 Subject: [PATCH] core: Skip private /tmp for generators in manager test runs For manager test runs, the generator output paths are located in /tmp, which means that if we mount a private /tmp for generators, we lose all the generated units (actually the generators will just fail because the directories don't exist, but if they did exist, we'd still lose all the units). Let's avoid the problem by skipping the private /tmp for manager test runs. This also avoids any possible privilege issues with mounting a private /tmp that might happen in this scenario. --- src/core/manager.c | 2 +- test/units/TEST-65-ANALYZE.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/manager.c b/src/core/manager.c index 43fbd0e1e4..90e72b0c02 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -4161,7 +4161,7 @@ static int manager_run_generators(Manager *m) { /* On some systems /tmp/ doesn't exist, and on some other systems we cannot create it at all. Avoid * trying to mount a private tmpfs on it as there's no one size fits all. */ - if (is_dir("/tmp", /* follow= */ false) > 0) + if (is_dir("/tmp", /* follow= */ false) > 0 && !MANAGER_IS_TEST_RUN(m)) flags |= FORK_PRIVATE_TMP; r = safe_fork("(sd-gens)", flags, NULL); diff --git a/test/units/TEST-65-ANALYZE.sh b/test/units/TEST-65-ANALYZE.sh index 59dfd4fb57..5f650ade05 100755 --- a/test/units/TEST-65-ANALYZE.sh +++ b/test/units/TEST-65-ANALYZE.sh @@ -302,6 +302,9 @@ systemd-analyze security --offline=true /tmp/testfile.service # Ensure we print the list of ACLs, see https://github.com/systemd/systemd/issues/23185 systemd-analyze security --offline=true /tmp/testfile.service | grep -q -F "/dev/sda" +# Make sure that running generators under systemd-analyze verify works. +systemd-analyze verify --generators /tmp/testfile.service + rm /tmp/testfile.service cat </tmp/img/usr/lib/systemd/system/testfile.service