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;
}
+11 -7
View File
@@ -64,6 +64,7 @@ assert_cc(EAGAIN == EWOULDBLOCK);
int saved_argc = 0;
char **saved_argv = NULL;
static int saved_in_initrd = -1;
size_t page_size(void) {
static thread_local size_t pgsz = 0;
@@ -454,11 +455,10 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
}
bool in_initrd(void) {
static int saved = -1;
struct statfs s;
if (saved >= 0)
return saved;
if (saved_in_initrd >= 0)
return saved_in_initrd;
/* We make two checks here:
*
@@ -470,11 +470,15 @@ bool in_initrd(void) {
* emptying when transititioning to the main systemd.
*/
saved = access("/etc/initrd-release", F_OK) >= 0 &&
statfs("/", &s) >= 0 &&
is_temporary_fs(&s);
saved_in_initrd = access("/etc/initrd-release", F_OK) >= 0 &&
statfs("/", &s) >= 0 &&
is_temporary_fs(&s);
return saved;
return saved_in_initrd;
}
void in_initrd_force(bool value) {
saved_in_initrd = value;
}
/* hey glibc, APIs with callbacks without a user pointer are so useless */
+1
View File
@@ -86,6 +86,7 @@ int prot_from_flags(int flags) _const_;
int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...);
bool in_initrd(void);
void in_initrd_force(bool value);
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
int (*compar) (const void *, const void *, void *),