]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
proc-cmdline: make proc_cmdline_get_bool() take flags
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Aug 2023 08:41:55 +0000 (17:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Aug 2023 08:46:41 +0000 (17:46 +0900)
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.

src/basic/proc-cmdline.c
src/basic/proc-cmdline.h
src/core/main.c
src/firstboot/firstboot.c
src/partition/repart.c
src/shared/cgroup-setup.c
src/shared/condition.c
src/shared/reboot-util.c
src/sulogin-shell/sulogin-shell.c
src/test/test-proc-cmdline.c
src/udev/net/link-config.c

index 32d4f414cc4c8d774b4b08ca5c7578fdac402fe2..95130a36be33153dfb449cf718031c2076c1cd9e 100644 (file)
@@ -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 */
index a64d7757bcc8d1176450d2f1dc2ec538b1c83d05..babdcbeeaac41381ba94b67ca2042249aaf0c3fc 100644 (file)
@@ -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)
index 822825ca6fb1426e393e5f7ff2b33753ac01abb4..c929b88db6bd19bcbe536d50c196cc18a9f22b1c 100644 (file)
@@ -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");
 
index 1956ab3b1356fc2dc098b9e858637320e3dd585e..59d4dcd118f85c4eeb6bb6b2913dedce5a36e3c9 100644 (file)
@@ -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) {
index c87f42346dbb1cc6826edae4175fe0b90ba67c88..afe0dcc7fb750e5581ae9b1d6a288e29858c18dc 100644 (file)
@@ -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) {
index 1dc56b11adde20927464db84a5341f0557de1144..c35fd460bd39f119675587614e555901cf31b79b 100644 (file)
@@ -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. */
index 092f32a69ed9aee772d823bf6cef7db365306487..06fcd71be583b27f0f16313a87e972e4bdea1108 100644 (file)
@@ -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)
index a010bf6e7f28c5f6a470afda3c041b1a6daaef54..75910ede4413b85f45c2035cc63fe597d8a63fb0 100644 (file)
@@ -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;
 
index 7ffafcda553e66f1616b9bb5304b883a0d233baa..f2de30cc3fa4aee79a363c28f969df45b16ecb69 100644 (file)
@@ -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");
         }
index 4fd91253781c6695bb8a72c56679da76c60591f3..3614ebe6f4382553aca2e56a198df94ee1912ed3 100644 (file)
@@ -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
 
index b554a6827d4ff5684eac69a547e18fdb23651400..ff8fb24f6695385edff4497575ee0398aad20a93 100644 (file)
@@ -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)