diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-08-29 11:10:18 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-09-01 23:16:13 +0200 |
commit | c9907425238bdfd07c0a054debb3232ea2a944ef (patch) | |
tree | 1ba6bb207372814eb07d877f377e08d78fb9ed67 /src/shared/condition.c | |
parent | compare: add macro for operator charset (diff) | |
download | systemd-c9907425238bdfd07c0a054debb3232ea2a944ef.tar.xz systemd-c9907425238bdfd07c0a054debb3232ea2a944ef.zip |
condition: allow fnmatch() matches in ConditionKernelVersion=
This is mostly to make things systematic, and brings no new
functionality, as not specifying any operator is identical to prefixing
with =$ anyway.
Diffstat (limited to 'src/shared/condition.c')
-rw-r--r-- | src/shared/condition.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/shared/condition.c b/src/shared/condition.c index 2d9979b9c4..f893937156 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -206,30 +206,30 @@ static int condition_test_kernel_version(Condition *c, char **env) { break; s = strstrip(word); - operator = parse_compare_operator(&s, 0); - if (operator >= 0) { - s += strspn(s, WHITESPACE); - if (isempty(s)) { - if (first) { - /* For backwards compatibility, allow whitespace between the operator and - * value, without quoting, but only in the first expression. */ - word = mfree(word); - r = extract_first_word(&p, &word, NULL, 0); - if (r < 0) - return log_debug_errno(r, "Failed to parse condition string \"%s\": %m", p); - if (r == 0) - return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Unexpected end of expression: %s", p); - s = word; - } else + operator = parse_compare_operator(&s, COMPARE_ALLOW_FNMATCH); + if (operator < 0) /* No prefix? Then treat as glob string */ + operator = COMPARE_FNMATCH_EQUAL; + + s += strspn(s, WHITESPACE); + if (isempty(s)) { + if (first) { + /* For backwards compatibility, allow whitespace between the operator and + * value, without quoting, but only in the first expression. */ + word = mfree(word); + r = extract_first_word(&p, &word, NULL, 0); + if (r < 0) + return log_debug_errno(r, "Failed to parse condition string \"%s\": %m", p); + if (r == 0) return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Unexpected end of expression: %s", p); - } - - r = test_order(strverscmp_improved(u.release, s), operator); - } else - /* No prefix? Then treat as glob string */ - r = fnmatch(s, u.release, 0) == 0; + s = word; + } else + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Unexpected end of expression: %s", p); + } - if (r == 0) + r = version_or_fnmatch_compare(operator, u.release, s); + if (r < 0) + return r; + if (!r) return false; first = false; |