]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pid1: use initrd.target in the initramfs by default
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Nov 2019 08:48:26 +0000 (09:48 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Nov 2019 18:59:33 +0000 (19:59 +0100)
This makes the code do what the documentation says. The code had no inkling
about initrd.target, so I think this change is fairly risky. As a fallback,
default.target will be loaded, so initramfses which relied on current behaviour
will still work, as along as they don't have a different initrd.target.

In an initramfs created with recent dracut:
$ ls -l usr/lib/systemd/system/{default.target,initrd.target}
lrwxrwxrwx. usr/lib/systemd/system/default.target -> initrd.target
-rw-r--r--. usr/lib/systemd/system/initrd.target
So at least for dracut, there should be no difference.

Also avoid a pointless allocation.

src/basic/special.h
src/core/main.c

index add1c1d507e87fae81056934c597619c97d69267..0eb3f3a36866ddd1a7f6ff251468429f1a8aec9c 100644 (file)
@@ -2,6 +2,7 @@
 #pragma once
 
 #define SPECIAL_DEFAULT_TARGET "default.target"
+#define SPECIAL_INITRD_TARGET "initrd.target"
 
 /* Shutdown targets */
 #define SPECIAL_UMOUNT_TARGET "umount.target"
index 6e101f02785cd366636e93612718a81cf58a362c..ff9058aadb16182cc04027339c5b5d1432cbe3c1 100644 (file)
@@ -1967,20 +1967,36 @@ static int do_queue_default_job(
                 const char **ret_error_message) {
 
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+        const char* default_unit;
         Job *default_unit_job;
         Unit *target = NULL;
         int r;
 
-        log_debug("Activating default unit: %s", arg_default_unit);
+        if (arg_default_unit)
+                default_unit = arg_default_unit;
+        else if (in_initrd())
+                default_unit = SPECIAL_INITRD_TARGET;
+        else
+                default_unit = SPECIAL_DEFAULT_TARGET;
+
+        log_debug("Activating default unit: %s", default_unit);
+
+        r = manager_load_startable_unit_or_warn(m, default_unit, NULL, &target);
+        if (r < 0 && in_initrd() && !arg_default_unit) {
+                /* Fall back to default.target, which we used to always use by default. Only do this if no
+                 * explicit configuration was given. */
+
+                log_info("Falling back to " SPECIAL_DEFAULT_TARGET ".");
 
-        r = manager_load_startable_unit_or_warn(m, arg_default_unit, NULL, &target);
+                r = manager_load_startable_unit_or_warn(m, SPECIAL_DEFAULT_TARGET, NULL, &target);
+        }
         if (r < 0) {
-                log_info("Falling back to rescue target: " SPECIAL_RESCUE_TARGET);
+                log_info("Falling back to " SPECIAL_RESCUE_TARGET ".");
 
                 r = manager_load_startable_unit_or_warn(m, SPECIAL_RESCUE_TARGET, NULL, &target);
                 if (r < 0) {
-                        *ret_error_message = r == -ERFKILL ? "Rescue target masked"
-                                                           : "Failed to load rescue target";
+                        *ret_error_message = r == -ERFKILL ? SPECIAL_RESCUE_TARGET " masked"
+                                                           : "Failed to load " SPECIAL_RESCUE_TARGET;
                         return r;
                 }
         }
@@ -2192,15 +2208,6 @@ static int load_configuration(
                 return r;
         }
 
-        /* Initialize default unit */
-        if (!arg_default_unit) {
-                arg_default_unit = strdup(SPECIAL_DEFAULT_TARGET);
-                if (!arg_default_unit) {
-                        *ret_error_message = "Failed to set default unit";
-                        return log_oom();
-                }
-        }
-
         /* Initialize the show status setting if it hasn't been set explicitly yet */
         if (arg_show_status == _SHOW_STATUS_INVALID)
                 arg_show_status = SHOW_STATUS_YES;