]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: relax dependency on RootImage= storage from Requires= to Wants=
authorLuca Boccassi <bluca@debian.org>
Mon, 27 Nov 2023 23:32:31 +0000 (23:32 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 8 Dec 2023 02:16:31 +0000 (11:16 +0900)
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=.

src/core/unit.c
test/TEST-82-SOFTREBOOT/test.sh
test/units/testsuite-82.sh

index d29dc77bdbbea6ede812501e040f81507426c270..b407387fc134a03ff22c1f4b1a71c734b230c8c5 100644 (file)
@@ -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;
         }
index 049414918567804844a91146284ea26a1d8f0780..3c0676b39b24f73684f3171cd3d7890e70aeca48 100755 (executable)
@@ -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 "$@"
index b5e6dedfed5f6b7989bbdc9cbf164cbaec7f46bd..224cd75c7fead009a23de405f186dd1b90d8eade 100755 (executable)
@@ -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 \