diff options
Diffstat (limited to '')
-rw-r--r-- | src/basic/proc-cmdline.c | 44 | ||||
-rw-r--r-- | src/basic/proc-cmdline.h | 1 | ||||
-rw-r--r-- | src/debug-generator/debug-generator.c | 1 | ||||
-rw-r--r-- | src/shared/unit-file.c | 45 | ||||
-rw-r--r-- | src/shared/unit-file.h | 2 | ||||
-rw-r--r-- | src/system-update-generator/system-update-generator.c | 1 | ||||
-rw-r--r-- | src/test/test-proc-cmdline.c | 19 | ||||
-rw-r--r-- | src/test/test-unit-file.c | 20 |
8 files changed, 69 insertions, 64 deletions
diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c index 09169cf963..5d29774e09 100644 --- a/src/basic/proc-cmdline.c +++ b/src/basic/proc-cmdline.c @@ -317,47 +317,3 @@ int shall_restore_state(void) { return r > 0 ? ret : true; } - -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, - NULL -}; - -static const char * const rlmap_initrd[] = { - "emergency", SPECIAL_EMERGENCY_TARGET, - "rescue", SPECIAL_RESCUE_TARGET, - NULL -}; - -const char* runlevel_to_target(const char *word) { - const char * const *rlmap_ptr; - size_t i; - - if (!word) - return NULL; - - if (in_initrd()) { - word = startswith(word, "rd."); - if (!word) - return NULL; - } - - rlmap_ptr = in_initrd() ? rlmap_initrd : rlmap; - - for (i = 0; rlmap_ptr[i]; i += 2) - if (streq(word, rlmap_ptr[i])) - return rlmap_ptr[i+1]; - - return NULL; -} diff --git a/src/basic/proc-cmdline.h b/src/basic/proc-cmdline.h index ff04379fbd..429e7ca4a4 100644 --- a/src/basic/proc-cmdline.h +++ b/src/basic/proc-cmdline.h @@ -28,7 +28,6 @@ char *proc_cmdline_key_startswith(const char *s, const char *prefix); bool proc_cmdline_key_streq(const char *x, const char *y); int shall_restore_state(void); -const char* runlevel_to_target(const char *rl); /* A little helper call, to be used in proc_cmdline_parse_t callbacks */ static inline bool proc_cmdline_value_missing(const char *key, const char *value) { diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index e73dde32b8..bc8714c4c7 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -12,6 +12,7 @@ #include "special.h" #include "string-util.h" #include "strv.h" +#include "unit-file.h" #include "unit-name.h" static const char *arg_dest = NULL; diff --git a/src/shared/unit-file.c b/src/shared/unit-file.c index 4a5f23e6c1..9bcd5dc92e 100644 --- a/src/shared/unit-file.c +++ b/src/shared/unit-file.c @@ -6,6 +6,7 @@ #include "macro.h" #include "path-lookup.h" #include "set.h" +#include "special.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" @@ -511,3 +512,47 @@ int unit_file_find_fragment( // FIXME: if instance, consider any unit names with different template name return 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, + NULL +}; + +static const char * const rlmap_initrd[] = { + "emergency", SPECIAL_EMERGENCY_TARGET, + "rescue", SPECIAL_RESCUE_TARGET, + NULL +}; + +const char* runlevel_to_target(const char *word) { + const char * const *rlmap_ptr; + size_t i; + + if (!word) + return NULL; + + if (in_initrd()) { + word = startswith(word, "rd."); + if (!word) + return NULL; + } + + rlmap_ptr = in_initrd() ? rlmap_initrd : rlmap; + + for (i = 0; rlmap_ptr[i]; i += 2) + if (streq(word, rlmap_ptr[i])) + return rlmap_ptr[i+1]; + + return NULL; +} diff --git a/src/shared/unit-file.h b/src/shared/unit-file.h index 54cc7876fe..98ba677f3f 100644 --- a/src/shared/unit-file.h +++ b/src/shared/unit-file.h @@ -54,3 +54,5 @@ int unit_file_find_fragment( const char *unit_name, const char **ret_fragment_path, Set **names); + +const char* runlevel_to_target(const char *rl); diff --git a/src/system-update-generator/system-update-generator.c b/src/system-update-generator/system-update-generator.c index 6ec4986c10..666affca19 100644 --- a/src/system-update-generator/system-update-generator.c +++ b/src/system-update-generator/system-update-generator.c @@ -9,6 +9,7 @@ #include "proc-cmdline.h" #include "special.h" #include "string-util.h" +#include "unit-file.h" #include "util.h" /* diff --git a/src/test/test-proc-cmdline.c b/src/test/test-proc-cmdline.c index 6d25a6919e..884fb36010 100644 --- a/src/test/test-proc-cmdline.c +++ b/src/test/test-proc-cmdline.c @@ -212,24 +212,6 @@ static void test_proc_cmdline_key_startswith(void) { assert_se(!proc_cmdline_key_startswith("foo-bar", "foo_xx")); } -static void test_runlevel_to_target(void) { - log_info("/* %s */", __func__); - - in_initrd_force(false); - 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("rd.unknown-runlevel"), NULL)); - assert_se(streq_ptr(runlevel_to_target("3"), SPECIAL_MULTI_USER_TARGET)); - assert_se(streq_ptr(runlevel_to_target("rd.rescue"), NULL)); - - in_initrd_force(true); - 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("rd.unknown-runlevel"), NULL)); - assert_se(streq_ptr(runlevel_to_target("3"), NULL)); - assert_se(streq_ptr(runlevel_to_target("rd.rescue"), SPECIAL_RESCUE_TARGET)); -} - int main(void) { log_parse_environment(); log_open(); @@ -244,7 +226,6 @@ int main(void) { test_proc_cmdline_get_key(); test_proc_cmdline_get_bool(); test_proc_cmdline_get_key_many(); - test_runlevel_to_target(); return 0; } diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index 8bc5bf6038..f0186b078f 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -2,6 +2,7 @@ #include "path-lookup.h" #include "set.h" +#include "special.h" #include "strv.h" #include "tests.h" #include "unit-file.h" @@ -75,11 +76,30 @@ static void test_unit_file_build_name_map(char **ids) { } } +static void test_runlevel_to_target(void) { + log_info("/* %s */", __func__); + + in_initrd_force(false); + 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("rd.unknown-runlevel"), NULL)); + assert_se(streq_ptr(runlevel_to_target("3"), SPECIAL_MULTI_USER_TARGET)); + assert_se(streq_ptr(runlevel_to_target("rd.rescue"), NULL)); + + in_initrd_force(true); + 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("rd.unknown-runlevel"), NULL)); + assert_se(streq_ptr(runlevel_to_target("3"), NULL)); + assert_se(streq_ptr(runlevel_to_target("rd.rescue"), SPECIAL_RESCUE_TARGET)); +} + int main(int argc, char **argv) { test_setup_logging(LOG_DEBUG); test_unit_validate_alias_symlink_and_warn(); test_unit_file_build_name_map(strv_skip(argv, 1)); + test_runlevel_to_target(); return 0; } |