From 7d95229ba7b4e5e862794647c367bcdc8237c8b6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 26 Oct 2018 12:02:55 +0200 Subject: [PATCH] proc-cmdline: teach proc_cmdline_get_key() the same flags magic as proc_cmdline_parse() --- src/basic/proc-cmdline.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c index b8839ef52cb..205ea08f6da 100644 --- a/src/basic/proc-cmdline.c +++ b/src/basic/proc-cmdline.c @@ -159,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) @@ -167,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; @@ -188,7 +198,7 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) { found = true; } else { - if (streq(word, key)) + if (streq(k, key)) found = true; } }