From: Yu Watanabe Date: Wed, 9 Aug 2023 08:41:55 +0000 (+0900) Subject: proc-cmdline: make proc_cmdline_get_bool() take flags X-Git-Tag: v255-rc1~780^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3787934b54822e6d6fcfd95dd2a5157c1d1b2212;p=thirdparty%2Fsystemd.git proc-cmdline: make proc_cmdline_get_bool() take flags All other command line parsers takes flags. Let's make proc_cmdline_get_bool() also take flags. Though, currently, no flag is set by the caller. --- diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c index 32d4f414cc4..95130a36be3 100644 --- a/src/basic/proc-cmdline.c +++ b/src/basic/proc-cmdline.c @@ -392,13 +392,13 @@ int proc_cmdline_get_key(const char *key, ProcCmdlineFlags flags, char **ret_val return cmdline_get_key(args, key, flags, ret_value); } -int proc_cmdline_get_bool(const char *key, bool *ret) { +int proc_cmdline_get_bool(const char *key, ProcCmdlineFlags flags, bool *ret) { _cleanup_free_ char *v = NULL; int r; assert(ret); - r = proc_cmdline_get_key(key, PROC_CMDLINE_VALUE_OPTIONAL, &v); + r = proc_cmdline_get_key(key, flags | PROC_CMDLINE_VALUE_OPTIONAL, &v); if (r < 0) return r; if (r == 0) { /* key not specified at all */ diff --git a/src/basic/proc-cmdline.h b/src/basic/proc-cmdline.h index a64d7757bcc..babdcbeeaac 100644 --- a/src/basic/proc-cmdline.h +++ b/src/basic/proc-cmdline.h @@ -22,7 +22,7 @@ int proc_cmdline_strv(char ***ret); int proc_cmdline_parse(const proc_cmdline_parse_t parse, void *userdata, ProcCmdlineFlags flags); int proc_cmdline_get_key(const char *parameter, ProcCmdlineFlags flags, char **value); -int proc_cmdline_get_bool(const char *key, bool *ret); +int proc_cmdline_get_bool(const char *key, ProcCmdlineFlags flags, bool *ret); int proc_cmdline_get_key_many_internal(ProcCmdlineFlags flags, ...); #define proc_cmdline_get_key_many(flags, ...) proc_cmdline_get_key_many_internal(flags, __VA_ARGS__, NULL) diff --git a/src/core/main.c b/src/core/main.c index 822825ca6fb..c929b88db6b 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -2183,7 +2183,7 @@ static void log_execution_mode(bool *ret_first_boot) { /* Let's check whether we are in first boot. First, check if an override was * specified on the kernel commandline. If yes, we honour that. */ - r = proc_cmdline_get_bool("systemd.condition-first-boot", &first_boot); + r = proc_cmdline_get_bool("systemd.condition-first-boot", /* flags = */ 0, &first_boot); if (r < 0) log_debug_errno(r, "Failed to parse systemd.condition-first-boot= kernel commandline argument, ignoring: %m"); diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 1956ab3b135..59d4dcd118f 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -1650,7 +1650,7 @@ static int run(int argc, char *argv[]) { * opposed to some other file system tree/image) */ bool enabled; - r = proc_cmdline_get_bool("systemd.firstboot", &enabled); + r = proc_cmdline_get_bool("systemd.firstboot", /* flags = */ 0, &enabled); if (r < 0) return log_error_errno(r, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m"); if (r > 0 && !enabled) { diff --git a/src/partition/repart.c b/src/partition/repart.c index c87f42346db..afe0dcc7fb7 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -6690,7 +6690,7 @@ static int parse_proc_cmdline_factory_reset(void) { if (!in_initrd()) /* Never honour kernel command line factory reset request outside of the initrd */ return 0; - r = proc_cmdline_get_bool("systemd.factory_reset", &b); + r = proc_cmdline_get_bool("systemd.factory_reset", /* flags = */ 0, &b); if (r < 0) return log_error_errno(r, "Failed to parse systemd.factory_reset kernel command line argument: %m"); if (r > 0) { diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index 1dc56b11add..c35fd460bd3 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -96,7 +96,7 @@ bool cg_is_unified_wanted(void) { return (wanted = r >= CGROUP_UNIFIED_ALL); /* If we were explicitly passed systemd.unified_cgroup_hierarchy, respect that. */ - r = proc_cmdline_get_bool("systemd.unified_cgroup_hierarchy", &b); + r = proc_cmdline_get_bool("systemd.unified_cgroup_hierarchy", /* flags = */ 0, &b); if (r > 0) return (wanted = b); @@ -147,7 +147,7 @@ bool cg_is_hybrid_wanted(void) { /* Otherwise, let's see what the kernel command line has to say. Since checking is expensive, cache * a non-error result. */ - r = proc_cmdline_get_bool("systemd.legacy_systemd_cgroup_controller", &b); + r = proc_cmdline_get_bool("systemd.legacy_systemd_cgroup_controller", /* flags = */ 0, &b); /* The meaning of the kernel option is reversed wrt. to the return value of this function, hence the * negation. */ diff --git a/src/shared/condition.c b/src/shared/condition.c index 092f32a69ed..06fcd71be58 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -748,7 +748,7 @@ static int condition_test_needs_update(Condition *c, char **env) { assert(c->parameter); assert(c->type == CONDITION_NEEDS_UPDATE); - r = proc_cmdline_get_bool("systemd.condition-needs-update", &b); + r = proc_cmdline_get_bool("systemd.condition-needs-update", /* flags = */ 0, &b); if (r < 0) log_debug_errno(r, "Failed to parse systemd.condition-needs-update= kernel command line argument, ignoring: %m"); if (r > 0) diff --git a/src/shared/reboot-util.c b/src/shared/reboot-util.c index a010bf6e7f2..75910ede441 100644 --- a/src/shared/reboot-util.c +++ b/src/shared/reboot-util.c @@ -113,7 +113,7 @@ int shall_restore_state(void) { bool ret; int r; - r = proc_cmdline_get_bool("systemd.restore_state", &ret); + r = proc_cmdline_get_bool("systemd.restore_state", /* flags = */ 0, &ret); if (r < 0) return r; diff --git a/src/sulogin-shell/sulogin-shell.c b/src/sulogin-shell/sulogin-shell.c index 7ffafcda553..f2de30cc3fa 100644 --- a/src/sulogin-shell/sulogin-shell.c +++ b/src/sulogin-shell/sulogin-shell.c @@ -109,7 +109,7 @@ static int run(int argc, char *argv[]) { /* We look the argument in the kernel cmdline under the same name as the environment variable * to express that this is not supported at the same level as the regular kernel cmdline * switches. */ - r = proc_cmdline_get_bool("SYSTEMD_SULOGIN_FORCE", &force); + r = proc_cmdline_get_bool("SYSTEMD_SULOGIN_FORCE", /* flags = */ 0, &force); if (r < 0) log_debug_errno(r, "Failed to parse SYSTEMD_SULOGIN_FORCE from kernel command line, ignoring: %m"); } diff --git a/src/test/test-proc-cmdline.c b/src/test/test-proc-cmdline.c index 4fd91253781..3614ebe6f43 100644 --- a/src/test/test-proc-cmdline.c +++ b/src/test/test-proc-cmdline.c @@ -178,19 +178,19 @@ TEST(proc_cmdline_get_bool) { assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0); assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=") == 0); - assert_se(proc_cmdline_get_bool("", &value) == -EINVAL); - assert_se(proc_cmdline_get_bool("abc", &value) == 0 && value == false); - assert_se(proc_cmdline_get_bool("foo_bar", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("foo-bar", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("bar-waldo", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("bar_waldo", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("x_y-z", &value) > 0 && value == false); - assert_se(proc_cmdline_get_bool("x-y-z", &value) > 0 && value == false); - assert_se(proc_cmdline_get_bool("x-y_z", &value) > 0 && value == false); - assert_se(proc_cmdline_get_bool("x_y_z", &value) > 0 && value == false); - assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false); - assert_se(proc_cmdline_get_bool("da", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("the", &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("", /* flags = */ 0, &value) == -EINVAL); + assert_se(proc_cmdline_get_bool("abc", /* flags = */ 0, &value) == 0 && value == false); + assert_se(proc_cmdline_get_bool("foo_bar", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("foo-bar", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("bar-waldo", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("bar_waldo", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("x_y-z", /* flags = */ 0, &value) > 0 && value == false); + assert_se(proc_cmdline_get_bool("x-y-z", /* flags = */ 0, &value) > 0 && value == false); + assert_se(proc_cmdline_get_bool("x-y_z", /* flags = */ 0, &value) > 0 && value == false); + assert_se(proc_cmdline_get_bool("x_y_z", /* flags = */ 0, &value) > 0 && value == false); + assert_se(proc_cmdline_get_bool("quux", /* flags = */ 0, &value) == -EINVAL && value == false); + assert_se(proc_cmdline_get_bool("da", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("the", /* flags = */ 0, &value) > 0 && value == true); } #if ENABLE_EFI @@ -200,19 +200,19 @@ TEST(proc_cmdline_get_bool_efi) { assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=") == 0); assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0); - assert_se(proc_cmdline_get_bool("", &value) == -EINVAL); - assert_se(proc_cmdline_get_bool("abc", &value) == 0 && value == false); - assert_se(proc_cmdline_get_bool("foo_bar", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("foo-bar", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("bar-waldo", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("bar_waldo", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("x_y-z", &value) > 0 && value == false); - assert_se(proc_cmdline_get_bool("x-y-z", &value) > 0 && value == false); - assert_se(proc_cmdline_get_bool("x-y_z", &value) > 0 && value == false); - assert_se(proc_cmdline_get_bool("x_y_z", &value) > 0 && value == false); - assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false); - assert_se(proc_cmdline_get_bool("da", &value) > 0 && value == true); - assert_se(proc_cmdline_get_bool("the", &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("", /* flags = */ 0, &value) == -EINVAL); + assert_se(proc_cmdline_get_bool("abc", /* flags = */ 0, &value) == 0 && value == false); + assert_se(proc_cmdline_get_bool("foo_bar", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("foo-bar", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("bar-waldo", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("bar_waldo", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("x_y-z", /* flags = */ 0, &value) > 0 && value == false); + assert_se(proc_cmdline_get_bool("x-y-z", /* flags = */ 0, &value) > 0 && value == false); + assert_se(proc_cmdline_get_bool("x-y_z", /* flags = */ 0, &value) > 0 && value == false); + assert_se(proc_cmdline_get_bool("x_y_z", /* flags = */ 0, &value) > 0 && value == false); + assert_se(proc_cmdline_get_bool("quux", /* flags = */ 0, &value) == -EINVAL && value == false); + assert_se(proc_cmdline_get_bool("da", /* flags = */ 0, &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("the", /* flags = */ 0, &value) > 0 && value == true); } #endif diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index b554a6827d4..ff8fb24f669 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -702,7 +702,7 @@ static bool enable_name_policy(void) { if (cached >= 0) return cached; - r = proc_cmdline_get_bool("net.ifnames", &b); + r = proc_cmdline_get_bool("net.ifnames", /* flags = */ 0, &b); if (r < 0) log_warning_errno(r, "Failed to parse net.ifnames= kernel command line option, ignoring: %m"); if (r <= 0)