]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
install: Fall back to system presets if there are no initrd presets 38790/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 2 Sep 2025 09:58:17 +0000 (11:58 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 4 Sep 2025 06:55:40 +0000 (08:55 +0200)
We might be operating with a newer systemctl on an image with older
systemd and thus without an initrd-preset directory. Before
4a8c395167c1631224c02d990c847955a2bf23b0, we would use the system
presets, let's make sure we keep doing that if we're operating on an
image without initrd presets.

Follow up for 4a8c395167c1631224c02d990c847955a2bf23b0.

src/shared/install.c

index 4ed6a0962a4c8ff832b081951fad04270ead0d39..81954365642d9aad577c95631ff5fe79904d39ed 100644 (file)
@@ -3298,7 +3298,20 @@ static int presets_find_config(RuntimeScope scope, const char *root_dir, char **
                 if (r < 0 && r != -ENOENT)
                         return r;
 
-                dirs = r >= 0 ? initrd_dirs : system_dirs;
+                /* Make sure that we fall back to the system preset directories if we're operating on a root
+                 * directory without initrd preset directories. This makes sure that we don't regress when
+                 * using a newer systemctl to operate on a root directory with an older version of systemd
+                 * installed that doesn't yet known about initrd preset directories. */
+                if (r >= 0)
+                        STRV_FOREACH(d, initrd_dirs) {
+                                r = chase_and_access(*d, root_dir, CHASE_PREFIX_ROOT, F_OK, /* ret_path= */ NULL);
+                                if (r >= 0)
+                                        return conf_files_list_strv(ret, ".preset", root_dir, 0, initrd_dirs);
+                                if (r != -ENOENT)
+                                        return r;
+                        }
+
+                dirs = system_dirs;
         } else if (IN_SET(scope, RUNTIME_SCOPE_GLOBAL, RUNTIME_SCOPE_USER))
                 dirs = user_dirs;
         else