From: Luca Boccassi Date: Mon, 27 Nov 2023 23:32:31 +0000 (+0000) Subject: core: relax dependency on RootImage= storage from Requires= to Wants= X-Git-Tag: v256-rc1~1550 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ebc751038018ece35675c04422e03a3685aaf79f;p=thirdparty%2Fsystemd.git core: relax dependency on RootImage= storage from Requires= to Wants= If a unit is running in an image and wants to survive a soft-reboot, then it can't be deactivated by the storage of the image going away. Relax the dependency to a Wants=. Access to the image is not needed when the unit is running anyway, so downgrade to Wants=. --- diff --git a/src/core/unit.c b/src/core/unit.c index d29dc77bdbb..b407387fc13 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1289,13 +1289,13 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) { } if (c->root_directory) { - r = unit_add_mounts_for(u, c->root_directory, UNIT_DEPENDENCY_FILE, UNIT_MOUNT_REQUIRES); + r = unit_add_mounts_for(u, c->root_directory, UNIT_DEPENDENCY_FILE, UNIT_MOUNT_WANTS); if (r < 0) return r; } if (c->root_image) { - r = unit_add_mounts_for(u, c->root_image, UNIT_DEPENDENCY_FILE, UNIT_MOUNT_REQUIRES); + r = unit_add_mounts_for(u, c->root_image, UNIT_DEPENDENCY_FILE, UNIT_MOUNT_WANTS); if (r < 0) return r; } diff --git a/test/TEST-82-SOFTREBOOT/test.sh b/test/TEST-82-SOFTREBOOT/test.sh index 04941491856..3c0676b39b2 100755 --- a/test/TEST-82-SOFTREBOOT/test.sh +++ b/test/TEST-82-SOFTREBOOT/test.sh @@ -7,8 +7,21 @@ TEST_DESCRIPTION="Test Soft-Rebooting" IGNORE_MISSING_COVERAGE=yes # Prevent shutdown in test suite, the expect script does that manually. TEST_SKIP_SHUTDOWN=yes +IMAGE_NAME="softreboot" +TEST_NO_NSPAWN=1 +TEST_INSTALL_VERITY_MINIMAL=1 # shellcheck source=test/test-functions . "$TEST_BASE_DIR/test-functions" +test_require_bin mksquashfs veritysetup sfdisk + +test_append_files() { + instmods squashfs =squashfs + instmods dm_verity =md + install_dmevent + generate_module_dependencies + install_verity_minimal +} + do_test "$@" diff --git a/test/units/testsuite-82.sh b/test/units/testsuite-82.sh index b5e6dedfed5..224cd75c7fe 100755 --- a/test/units/testsuite-82.sh +++ b/test/units/testsuite-82.sh @@ -181,6 +181,11 @@ EOF systemd-run --collect --service-type=notify -p DefaultDependencies=no -p IgnoreOnIsolate=yes --unit=testsuite-82-nosurvive-sigterm.service "$survive_sigterm" systemd-run --collect --service-type=exec -p DefaultDependencies=no -p IgnoreOnIsolate=yes --unit=testsuite-82-nosurvive.service sleep infinity + # Ensure that the unit doesn't get deactivated by dependencies on the source file. Given it's a verity + # image that is already open, even if the tmpfs with the image goes away, the file will be pinned by the + # kernel and will keep working. + cp /usr/share/minimal_0.* /tmp/ + # Configure these transient units to survive the soft reboot - they will not conflict with shutdown.target # and it will be ignored on the isolate that happens in the next boot. The first will use argv[0][0] = # '@', and the second will use SurviveFinalKillSignal=yes. Both should survive. @@ -193,6 +198,11 @@ EOF --property "Before=reboot.target kexec.target poweroff.target halt.target emergency.target rescue.target" \ "$survive_argv" systemd-run --service-type=exec --unit=testsuite-82-survive.service \ + --property TemporaryFileSystem="/run /tmp /var" \ + --property RootImage=/tmp/minimal_0.raw \ + --property BindReadOnlyPaths=/dev/log \ + --property BindReadOnlyPaths=/run/systemd/journal/socket \ + --property BindReadOnlyPaths=/run/systemd/journal/stdout \ --property SurviveFinalKillSignal=yes \ --property IgnoreOnIsolate=yes \ --property DefaultDependencies=no \