Merge pull request #28809 from YHNdnzj/proc-cmdline-true-when-missing

proc-cmdline: introduce PROC_CMDLINE_TRUE_WHEN_MISSING and use it where appropriate
This commit is contained in:
Yu Watanabe
2023-08-13 19:25:22 +09:00
committed by GitHub
9 changed files with 33 additions and 42 deletions
+12 -9
View File
@@ -197,10 +197,6 @@ static int proc_cmdline_parse_strv(char **args, proc_cmdline_parse_t parse_item,
assert(parse_item);
/* The PROC_CMDLINE_VALUE_OPTIONAL flag doesn't really make sense for proc_cmdline_parse(), let's
* make this clear. */
assert(!FLAGS_SET(flags, PROC_CMDLINE_VALUE_OPTIONAL));
STRV_FOREACH(word, args) {
char *key, *value;
@@ -226,6 +222,10 @@ int proc_cmdline_parse(proc_cmdline_parse_t parse_item, void *data, ProcCmdlineF
assert(parse_item);
/* The PROC_CMDLINE_VALUE_OPTIONAL and PROC_CMDLINE_TRUE_WHEN_MISSING flags don't really make sense
* for proc_cmdline_parse(), let's make this clear. */
assert(!(flags & (PROC_CMDLINE_VALUE_OPTIONAL|PROC_CMDLINE_TRUE_WHEN_MISSING)));
/* We parse the EFI variable first, because later settings have higher priority. */
if (!FLAGS_SET(flags, PROC_CMDLINE_IGNORE_EFI_OPTIONS)) {
@@ -351,6 +351,9 @@ int proc_cmdline_get_key(const char *key, ProcCmdlineFlags flags, char **ret_val
*
* In all three cases, > 0 is returned if the key is found, 0 if not. */
/* PROC_CMDLINE_TRUE_WHEN_MISSING doesn't really make sense for proc_cmdline_get_key(). */
assert(!FLAGS_SET(flags, PROC_CMDLINE_TRUE_WHEN_MISSING));
if (isempty(key))
return -EINVAL;
@@ -398,11 +401,11 @@ int proc_cmdline_get_bool(const char *key, ProcCmdlineFlags flags, bool *ret) {
assert(ret);
r = proc_cmdline_get_key(key, flags | PROC_CMDLINE_VALUE_OPTIONAL, &v);
r = proc_cmdline_get_key(key, (flags & ~PROC_CMDLINE_TRUE_WHEN_MISSING) | PROC_CMDLINE_VALUE_OPTIONAL, &v);
if (r < 0)
return r;
if (r == 0) { /* key not specified at all */
*ret = false;
*ret = FLAGS_SET(flags, PROC_CMDLINE_TRUE_WHEN_MISSING);
return 0;
}
@@ -456,9 +459,9 @@ int proc_cmdline_get_key_many_internal(ProcCmdlineFlags flags, ...) {
int r, ret = 0;
va_list ap;
/* The PROC_CMDLINE_VALUE_OPTIONAL flag doesn't really make sense for proc_cmdline_get_key_many(), let's make
* this clear. */
assert(!FLAGS_SET(flags, PROC_CMDLINE_VALUE_OPTIONAL));
/* The PROC_CMDLINE_VALUE_OPTIONAL and PROC_CMDLINE_TRUE_WHEN_MISSING flags don't really make sense
* for proc_cmdline_get_key_many, let's make this clear. */
assert(!(flags & (PROC_CMDLINE_VALUE_OPTIONAL|PROC_CMDLINE_TRUE_WHEN_MISSING)));
/* This call may clobber arguments on failure! */
+1
View File
@@ -10,6 +10,7 @@ typedef enum ProcCmdlineFlags {
PROC_CMDLINE_VALUE_OPTIONAL = 1 << 1, /* the value is optional (for boolean switches that can omit the value) */
PROC_CMDLINE_RD_STRICT = 1 << 2, /* ignore this in the initrd */
PROC_CMDLINE_IGNORE_EFI_OPTIONS = 1 << 3, /* don't check systemd's private EFI variable */
PROC_CMDLINE_TRUE_WHEN_MISSING = 1 << 4, /* default to true when the key is missing for bool */
} ProcCmdlineFlags;
typedef int (*proc_cmdline_parse_t)(const char *key, const char *value, void *data);