Skip to content

Commit 7d95229

Browse files
committed
proc-cmdline: teach proc_cmdline_get_key() the same flags magic as proc_cmdline_parse()
1 parent cb447ff commit 7d95229

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/basic/proc-cmdline.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,31 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
159159
p = line;
160160
for (;;) {
161161
_cleanup_free_ char *word = NULL;
162-
const char *e;
162+
const char *e, *k, *q;
163163

164164
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
165165
if (r < 0)
166166
return r;
167167
if (r == 0)
168168
break;
169169

170+
k = word;
171+
170172
/* Automatically filter out arguments that are intended only for the initrd, if we are not in the
171173
* initrd. */
172-
if (!in_initrd() && startswith(word, "rd."))
174+
q = startswith(word, "rd.");
175+
if (q) {
176+
if (!in_initrd())
177+
continue;
178+
179+
if (FLAGS_SET(flags, PROC_CMDLINE_STRIP_RD_PREFIX))
180+
k = q;
181+
182+
} else if (FLAGS_SET(flags, PROC_CMDLINE_RD_STRICT) && in_initrd())
173183
continue;
174184

175185
if (value) {
176-
e = proc_cmdline_key_startswith(word, key);
186+
e = proc_cmdline_key_startswith(k, key);
177187
if (!e)
178188
continue;
179189

@@ -188,7 +198,7 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
188198
found = true;
189199

190200
} else {
191-
if (streq(word, key))
201+
if (streq(k, key))
192202
found = true;
193203
}
194204
}

0 commit comments

Comments
 (0)