diff options
author | Evgeny Vereshchagin <evvers@ya.ru> | 2015-11-03 14:09:03 +0300 |
---|---|---|
committer | Evgeny Vereshchagin <evvers@ya.ru> | 2015-11-03 14:09:03 +0300 |
commit | c573dcfeb1abd390cd4c4288056df97752ef18f0 (patch) | |
tree | a04c3dae06f55ecaa7fb1af35b257b90a37d1ff8 /src | |
parent | 534e8f89d6367cd0e9e17fff67880fb430071d01 (diff) |
proc-cmdline: add runlevel to target mapping
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/proc-cmdline.c | 29 | ||||
-rw-r--r-- | src/basic/proc-cmdline.h | 1 | ||||
-rw-r--r-- | src/test/test-util.c | 8 |
3 files changed, 38 insertions, 0 deletions
diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c index dd91ce7dbc..f9f98af473 100644 --- a/src/basic/proc-cmdline.c +++ b/src/basic/proc-cmdline.c @@ -26,6 +26,7 @@ #include "parse-util.h" #include "proc-cmdline.h" #include "process-util.h" +#include "special.h" #include "string-util.h" #include "util.h" #include "virt.h" @@ -143,3 +144,31 @@ int shall_restore_state(void) { return parse_boolean(value) != 0; } + +static const char * const rlmap[] = { + "emergency", SPECIAL_EMERGENCY_TARGET, + "-b", SPECIAL_EMERGENCY_TARGET, + "rescue", SPECIAL_RESCUE_TARGET, + "single", SPECIAL_RESCUE_TARGET, + "-s", SPECIAL_RESCUE_TARGET, + "s", SPECIAL_RESCUE_TARGET, + "S", SPECIAL_RESCUE_TARGET, + "1", SPECIAL_RESCUE_TARGET, + "2", SPECIAL_MULTI_USER_TARGET, + "3", SPECIAL_MULTI_USER_TARGET, + "4", SPECIAL_MULTI_USER_TARGET, + "5", SPECIAL_GRAPHICAL_TARGET, +}; + +const char* runlevel_to_target(const char *word) { + size_t i; + + if (!word) + return NULL; + + for (i = 0; i < ELEMENTSOF(rlmap); i += 2) + if (streq(word, rlmap[i])) + return rlmap[i+1]; + + return NULL; +} diff --git a/src/basic/proc-cmdline.h b/src/basic/proc-cmdline.h index ea8277b053..ce6e84995a 100644 --- a/src/basic/proc-cmdline.h +++ b/src/basic/proc-cmdline.h @@ -26,3 +26,4 @@ int parse_proc_cmdline(int (*parse_word)(const char *key, const char *value)); int get_proc_cmdline_key(const char *parameter, char **value); int shall_restore_state(void); +const char* runlevel_to_target(const char *rl); diff --git a/src/test/test-util.c b/src/test/test-util.c index 647df4f5c3..f6ed55878c 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -48,6 +48,7 @@ #include "process-util.h" #include "rm-rf.h" #include "signal-util.h" +#include "special.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" @@ -1638,6 +1639,12 @@ cleanup: assert_se(rmdir(t) >= 0); } +static void test_runlevel_to_target(void) { + assert_se(streq_ptr(runlevel_to_target(NULL), NULL)); + assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL)); + assert_se(streq_ptr(runlevel_to_target("3"), SPECIAL_MULTI_USER_TARGET)); +} + int main(int argc, char *argv[]) { log_parse_environment(); log_open(); @@ -1718,6 +1725,7 @@ int main(int argc, char *argv[]) { test_tempfn(); test_strcmp_ptr(); test_fgetxattrat_fake(); + test_runlevel_to_target(); return 0; } |