core: automatically add dependency on systemd-remount-fs.service if StateDirectory...
authorLennart Poettering <lennart@poettering.net>
Wed, 8 Apr 2020 14:08:35 +0000 (16:08 +0200)
committerMichael Biebl <biebl@debian.org>
Mon, 27 Jul 2020 21:24:47 +0000 (22:24 +0100)
And similar for other settings that require a writable /var/.

Rationale: if these options are used for early-boot services (such as
systemd-pstore.service) we need /var/ writable. And if /var/ is on the
root fs, then systemd-remount-fs.service is the service that ensures
that /var/ is writable.

This allows us to remove explicit deps in services such as
systemd-pstore.service.

(cherry picked from commit f3b7a79b973a28af4f7a592a8b2e199cc194218b)

Gbp-Pq: Name core-automatically-add-dependency-on-systemd-remount-fs.s.patch

src/core/unit.c

index 2ddd0b39472229622300aad376e92368ddcf721b..5967d4a747f4b45bbf35cf7bfc92fc1a4bb5238c 100644 (file)
@@ -1046,6 +1046,16 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
         if (!MANAGER_IS_SYSTEM(u->manager))
                 return 0;
 
+        /* For the following three directory types we need write access, and /var/ is possibly on the root
+         * fs. Hence order after systemd-remount-fs.service, to ensure things are writable. */
+        if (!strv_isempty(c->directories[EXEC_DIRECTORY_STATE].paths) ||
+            !strv_isempty(c->directories[EXEC_DIRECTORY_CACHE].paths) ||
+            !strv_isempty(c->directories[EXEC_DIRECTORY_LOGS].paths)) {
+                r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_REMOUNT_FS_SERVICE, true, UNIT_DEPENDENCY_FILE);
+                if (r < 0)
+                        return r;
+        }
+
         if (c->private_tmp) {
                 const char *p;