From a8d3315ba410de0db154516d945b0731656a41d8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 9 Aug 2023 02:44:52 +0900 Subject: [PATCH] tree-wise: drop unnecessary use of proc_cmdline_key_streq() If the key does not contain '-' or '_', then it is not necessary to use proc_cmdline_key_streq(), and streq() is sufficient. This also adds missing assertions about 'key' argument. --- src/fstab-generator/fstab-generator.c | 2 ++ src/gpt-auto-generator/gpt-auto-generator.c | 10 +++++----- src/hibernate-resume/hibernate-resume-generator.c | 11 +++++++---- src/resolve/resolved-conf.c | 5 +++-- src/run-generator/run-generator.c | 4 +++- src/veritysetup/veritysetup-generator.c | 8 +++++--- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 041789673ff..c88f5d4b47d 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -1355,6 +1355,8 @@ static int add_mounts_from_creds(bool prefix_sysroot) { static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { int r; + assert(key); + /* root=, usr=, usrfstype= and roofstype= may occur more than once, the last * instance should take precedence. In the case of multiple rootflags= * or usrflags= the arguments should be concatenated */ diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index fed670e7f4a..ec047a14b52 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -904,7 +904,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat else arg_enabled = r; - } else if (proc_cmdline_key_streq(key, "root")) { + } else if (streq(key, "root")) { if (proc_cmdline_value_missing(key, value)) return 0; @@ -917,7 +917,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat log_debug("Disabling root partition auto-detection, root= is defined."); } - } else if (proc_cmdline_key_streq(key, "roothash")) { + } else if (streq(key, "roothash")) { if (proc_cmdline_value_missing(key, value)) return 0; @@ -941,14 +941,14 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (!strextend_with_separator(&arg_root_options, ",", value)) return log_oom(); - } else if (proc_cmdline_key_streq(key, "rw") && !value) + } else if (streq(key, "rw") && !value) arg_root_rw = true; - else if (proc_cmdline_key_streq(key, "ro") && !value) + else if (streq(key, "ro") && !value) arg_root_rw = false; else if (proc_cmdline_key_streq(key, "systemd.image_policy")) return parse_image_policy_argument(optarg, &arg_image_policy); - else if (proc_cmdline_key_streq(key, "systemd.swap")) { + else if (streq(key, "systemd.swap")) { r = value ? parse_boolean(value) : 1; if (r < 0) diff --git a/src/hibernate-resume/hibernate-resume-generator.c b/src/hibernate-resume/hibernate-resume-generator.c index fcd28892387..8b83ad6bdb3 100644 --- a/src/hibernate-resume/hibernate-resume-generator.c +++ b/src/hibernate-resume/hibernate-resume-generator.c @@ -56,7 +56,9 @@ typedef struct EFIHibernateLocation { static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { int r; - if (proc_cmdline_key_streq(key, "resume")) { + assert(key); + + if (streq(key, "resume")) { char *s; if (proc_cmdline_value_missing(key, value)) @@ -79,7 +81,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat arg_resume_offset_set = true; - } else if (proc_cmdline_key_streq(key, "resumeflags")) { + } else if (streq(key, "resumeflags")) { if (proc_cmdline_value_missing(key, value)) return 0; @@ -87,7 +89,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (!strextend_with_separator(&arg_resume_options, ",", value)) return log_oom(); - } else if (proc_cmdline_key_streq(key, "rootflags")) { + } else if (streq(key, "rootflags")) { if (proc_cmdline_value_missing(key, value)) return 0; @@ -95,7 +97,8 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (!strextend_with_separator(&arg_root_options, ",", value)) return log_oom(); - } else if (proc_cmdline_key_streq(key, "noresume")) { + } else if (streq(key, "noresume")) { + if (value) { log_warning("\"noresume\" kernel command line switch specified with an argument, ignoring."); return 0; diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index 94a579275fd..2f08ed0fe67 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -512,12 +512,13 @@ static int proc_cmdline_callback(const char *key, const char *value, void *data) struct ProcCmdlineInfo *info = ASSERT_PTR(data); int r; + assert(key); assert(info->manager); /* The kernel command line option names are chosen to be compatible with what various tools already * interpret, for example dracut and SUSE Linux. */ - if (proc_cmdline_key_streq(key, "nameserver")) { + if (streq(key, "nameserver")) { if (proc_cmdline_value_missing(key, value)) return 0; @@ -534,7 +535,7 @@ static int proc_cmdline_callback(const char *key, const char *value, void *data) info->manager->read_resolv_conf = false; - } else if (proc_cmdline_key_streq(key, "domain")) { + } else if (streq(key, "domain")) { if (proc_cmdline_value_missing(key, value)) return 0; diff --git a/src/run-generator/run-generator.c b/src/run-generator/run-generator.c index e3fb7f24fe6..dda7c36159e 100644 --- a/src/run-generator/run-generator.c +++ b/src/run-generator/run-generator.c @@ -26,7 +26,9 @@ STATIC_DESTRUCTOR_REGISTER(arg_failure_action, freep); static int parse(const char *key, const char *value, void *data) { int r; - if (proc_cmdline_key_streq(key, "systemd.run")) { + assert(key); + + if (streq(key, "systemd.run")) { if (proc_cmdline_value_missing(key, value)) return 0; diff --git a/src/veritysetup/veritysetup-generator.c b/src/veritysetup/veritysetup-generator.c index 303e0ced6d7..59ff4cd7a52 100644 --- a/src/veritysetup/veritysetup-generator.c +++ b/src/veritysetup/veritysetup-generator.c @@ -136,7 +136,9 @@ static int create_usr_device(void) { static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { int r; - if (proc_cmdline_key_streq(key, "systemd.verity")) { + assert(key); + + if (streq(key, "systemd.verity")) { r = value ? parse_boolean(value) : 1; if (r < 0) @@ -152,7 +154,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat else arg_read_veritytab = r; - } else if (proc_cmdline_key_streq(key, "roothash")) { + } else if (streq(key, "roothash")) { if (proc_cmdline_value_missing(key, value)) return 0; @@ -188,7 +190,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (r < 0) return log_oom(); - } else if (proc_cmdline_key_streq(key, "usrhash")) { + } else if (streq(key, "usrhash")) { if (proc_cmdline_value_missing(key, value)) return 0; -- 2.47.3