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.
This commit is contained in:
Daan De Meyer 2024-05-15 20:54:33 +02:00 committed by Zbigniew Jędrzejewski-Szmek
parent 742ee96dbe
commit 452f91d846
2 changed files with 4 additions and 1 deletions

View file

@ -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);

View file

@ -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 <<EOF >/tmp/img/usr/lib/systemd/system/testfile.service