chiark / gitweb /
core: parse `rd.rescue` and `rd.emergency` as initrd-specific shorthands (#3488)
authorIvan Shapovalov <intelfx@intelfx.name>
Mon, 13 Jun 2016 14:28:42 +0000 (18:28 +0400)
committerSven Eden <yamakuzure@gmx.net>
Fri, 16 Jun 2017 08:12:59 +0000 (10:12 +0200)
Typing `rd.rescue` is easier than `rd.elogind.unit=rescue.target`.

src/basic/proc-cmdline.c

index 62c801f..60a4e23 100644 (file)
@@ -161,17 +161,29 @@ static const char * const rlmap[] = {
         "3",         SPECIAL_MULTI_USER_TARGET,
         "4",         SPECIAL_MULTI_USER_TARGET,
         "5",         SPECIAL_GRAPHICAL_TARGET,
+        NULL
+};
+
+static const char * const rlmap_initrd[] = {
+        "emergency", SPECIAL_EMERGENCY_TARGET,
+        "rescue",    SPECIAL_RESCUE_TARGET,
+        NULL
 };
 
 const char* runlevel_to_target(const char *word) {
         size_t i;
+        const char * const *rlmap_ptr = in_initrd() ? rlmap_initrd
+                                                    : rlmap;
 
         if (!word)
                 return NULL;
 
-        for (i = 0; i < ELEMENTSOF(rlmap); i += 2)
-                if (streq(word, rlmap[i]))
-                        return rlmap[i+1];
+        if (in_initrd() && (word = startswith(word, "rd.")) == NULL)
+                return NULL;
+
+        for (i = 0; rlmap_ptr[i] != NULL; i += 2)
+                if (streq(word, rlmap_ptr[i]))
+                        return rlmap_ptr[i+1];
 
         return NULL;
 }