X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fcondition-util.c;h=026b6a8712593e972ca0166d61ec1fc84bc31244;hp=f88ddc19e29461e02d05b00639d8c7bbc9d789d1;hb=07318c290884824dd19f41beefb46aeaaabab46c;hpb=a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8 diff --git a/src/shared/condition-util.c b/src/shared/condition-util.c index f88ddc19e..026b6a871 100644 --- a/src/shared/condition-util.c +++ b/src/shared/condition-util.c @@ -26,7 +26,7 @@ #include #include -#include +#include "systemd/sd-id128.h" #include "util.h" #include "condition-util.h" #include "virt.h" @@ -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,33 +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; } - free(word); - free(line); - - return found == !c->negate; + return c->negate; } bool condition_test_virtualization(Condition *c) {