Merge pull request #10534 from poettering/cmdline-fixlets

proc-cmdline.c fixlets
This commit is contained in:
Lennart Poettering
2018-10-26 14:49:53 +02:00
committed by GitHub
2 changed files with 23 additions and 12 deletions
+20 -9
View File
@@ -64,10 +64,11 @@ int proc_cmdline_parse_given(const char *line, proc_cmdline_parse_t parse_item,
if (!in_initrd())
continue;
if (flags & PROC_CMDLINE_STRIP_RD_PREFIX)
if (FLAGS_SET(flags, PROC_CMDLINE_STRIP_RD_PREFIX))
key = q;
} else if (in_initrd() && flags & PROC_CMDLINE_RD_STRICT)
continue;
} else if (FLAGS_SET(flags, PROC_CMDLINE_RD_STRICT) && in_initrd())
continue; /* And optionally filter out arguments that are intended only for the host */
value = strchr(key, '=');
if (value)
@@ -148,7 +149,7 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
if (isempty(key))
return -EINVAL;
if ((flags & PROC_CMDLINE_VALUE_OPTIONAL) && !value)
if (FLAGS_SET(flags, PROC_CMDLINE_VALUE_OPTIONAL) && !value)
return -EINVAL;
r = proc_cmdline(&line);
@@ -158,7 +159,7 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
p = line;
for (;;) {
_cleanup_free_ char *word = NULL;
const char *e;
const char *e, *k, *q;
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
if (r < 0)
@@ -166,13 +167,23 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
if (r == 0)
break;
k = word;
/* Automatically filter out arguments that are intended only for the initrd, if we are not in the
* initrd. */
if (!in_initrd() && startswith(word, "rd."))
q = startswith(word, "rd.");
if (q) {
if (!in_initrd())
continue;
if (FLAGS_SET(flags, PROC_CMDLINE_STRIP_RD_PREFIX))
k = q;
} else if (FLAGS_SET(flags, PROC_CMDLINE_RD_STRICT) && in_initrd())
continue;
if (value) {
e = proc_cmdline_key_startswith(word, key);
e = proc_cmdline_key_startswith(k, key);
if (!e)
continue;
@@ -183,11 +194,11 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
found = true;
} else if (*e == 0 && (flags & PROC_CMDLINE_VALUE_OPTIONAL))
} else if (*e == 0 && FLAGS_SET(flags, PROC_CMDLINE_VALUE_OPTIONAL))
found = true;
} else {
if (streq(word, key))
if (streq(k, key))
found = true;
}
}
+3 -3
View File
@@ -6,9 +6,9 @@
#include "log.h"
enum {
PROC_CMDLINE_STRIP_RD_PREFIX = 1,
PROC_CMDLINE_VALUE_OPTIONAL = 2,
PROC_CMDLINE_RD_STRICT = 4
PROC_CMDLINE_STRIP_RD_PREFIX = 1 << 0,
PROC_CMDLINE_VALUE_OPTIONAL = 1 << 1,
PROC_CMDLINE_RD_STRICT = 1 << 2,
};
typedef int (*proc_cmdline_parse_t)(const char *key, const char *value, void *data);