summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-26 14:49:53 +0200
committerGitHub <noreply@github.com>2018-10-26 14:49:53 +0200
commit0ea63f7a7dbe9b7067b746fb7703d277d1444869 (patch)
treef54315702bfe4816dfd058410d2835e64838ae41 /src
parent2a1e0f2228bbdfbc18635e959f47df7da50b62fe (diff)
parent7d95229ba7b4e5e862794647c367bcdc8237c8b6 (diff)
downloadsystemd-0ea63f7a7dbe9b7067b746fb7703d277d1444869.tar.gz
systemd-0ea63f7a7dbe9b7067b746fb7703d277d1444869.tar.bz2
systemd-0ea63f7a7dbe9b7067b746fb7703d277d1444869.zip
Merge pull request #10534 from poettering/cmdline-fixlets
proc-cmdline.c fixlets
Diffstat (limited to 'src')
-rw-r--r--src/basic/proc-cmdline.c29
-rw-r--r--src/basic/proc-cmdline.h6
2 files changed, 23 insertions, 12 deletions
diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c
index 647c61ce73..205ea08f6d 100644
--- a/src/basic/proc-cmdline.c
+++ b/src/basic/proc-cmdline.c
@@ -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;
}
}
diff --git a/src/basic/proc-cmdline.h b/src/basic/proc-cmdline.h
index bb8b18d3b1..efa88df0a0 100644
--- a/src/basic/proc-cmdline.h
+++ b/src/basic/proc-cmdline.h
@@ -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);