1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 02:21:44 +03:00

proc-cmdline: teach proc_cmdline_get_key() the same flags magic as proc_cmdline_parse()

This commit is contained in:
Lennart Poettering 2018-10-26 12:02:55 +02:00
parent cb447ff5cc
commit 7d95229ba7

View File

@ -159,7 +159,7 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
p = line; p = line;
for (;;) { for (;;) {
_cleanup_free_ char *word = NULL; _cleanup_free_ char *word = NULL;
const char *e; const char *e, *k, *q;
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
if (r < 0) if (r < 0)
@ -167,13 +167,23 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
if (r == 0) if (r == 0)
break; break;
k = word;
/* Automatically filter out arguments that are intended only for the initrd, if we are not in the /* Automatically filter out arguments that are intended only for the initrd, if we are not in the
* initrd. */ * 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; continue;
if (value) { if (value) {
e = proc_cmdline_key_startswith(word, key); e = proc_cmdline_key_startswith(k, key);
if (!e) if (!e)
continue; continue;
@ -188,7 +198,7 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
found = true; found = true;
} else { } else {
if (streq(word, key)) if (streq(k, key))
found = true; found = true;
} }
} }