summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-11-05 19:43:55 +0100
committerLennart Poettering <lennart@poettering.net>2014-11-05 19:46:07 +0100
commit07318c290884824dd19f41beefb46aeaaabab46c (patch)
tree85b3e86f84668859b1f18bba0d757f8a9dd32ba8 /src/shared
parentd5ce1cfce46b9cf4e990acdcbae367785a56ed5e (diff)
condition: rewrite condition_test_kernel_command_line() based on unquote_first_word()
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/condition-util.c51
1 files changed, 22 insertions, 29 deletions
diff --git a/src/shared/condition-util.c b/src/shared/condition-util.c
index ff4a8ecd15..026b6a8712 100644
--- a/src/shared/condition-util.c
+++ b/src/shared/condition-util.c
@@ -74,12 +74,10 @@ void condition_free_list(Condition *first) {
}
bool condition_test_kernel_command_line(Condition *c) {
- char *line, *word = NULL;
- const char *w, *state;
+ _cleanup_free_ char *line = NULL;
+ const char *p;
bool equal;
int r;
- size_t l, pl;
- bool found = false;
assert(c);
assert(c->parameter);
@@ -92,35 +90,30 @@ bool condition_test_kernel_command_line(Condition *c) {
return c->negate;
equal = !!strchr(c->parameter, '=');
- pl = strlen(c->parameter);
-
- FOREACH_WORD_QUOTED(w, l, line, state) {
-
- free(word);
- word = strndup(w, l);
- if (!word)
- break;
-
- if (equal) {
- if (streq(word, c->parameter)) {
- found = true;
- break;
- }
- } else {
- if (startswith(word, c->parameter) && (word[pl] == '=' || word[pl] == 0)) {
- found = true;
- break;
- }
+ p = line;
+
+ for (;;) {
+ _cleanup_free_ char *word = NULL;
+ bool found;
+
+ r = unquote_first_word(&p, &word);
+ if (r <= 0)
+ return c->negate;
+
+ if (equal)
+ found = streq(word, c->parameter);
+ else {
+ const char *f;
+
+ f = startswith(word, c->parameter);
+ found = f && (*f == '=' || *f == 0);
}
+ if (found)
+ return !c->negate;
}
- if (!isempty(state))
- log_warning("Trailing garbage and the end of kernel commandline, ignoring.");
-
- free(word);
- free(line);
- return found == !c->negate;
+ return c->negate;
}
bool condition_test_virtualization(Condition *c) {