core: parse rd.rescue and rd.emergency as initrd-specific shorthands (#3488)

Typing `rd.rescue` is easier than `rd.systemd.unit=rescue.target`.
This commit is contained in:
Ivan Shapovalov
2016-06-13 16:28:42 +02:00
committed by Lennart Poettering
parent 68884a0b8a
commit dcd6145002
7 changed files with 50 additions and 18 deletions
+15 -3
View File
@@ -160,17 +160,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;
}