From 4803b0bcaa21616d2feb8e38998a95e28aa43d54 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Aug 2022 11:09:48 +0200 Subject: [PATCH] compare: add macro for operator charset --- src/shared/compare-operator.h | 3 +++ src/shared/condition.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/compare-operator.h b/src/shared/compare-operator.h index db5c2f0cfc9..900f3e54b20 100644 --- a/src/shared/compare-operator.h +++ b/src/shared/compare-operator.h @@ -4,6 +4,9 @@ #include #include +#define COMPARE_OPERATOR_CHARS "!<=>" +#define COMPARE_OPERATOR_WITH_FNMATCH_CHARS COMPARE_OPERATOR_CHARS "$" + typedef enum CompareOperator { /* Listed in order of checking. Note that some comparators are prefixes of others, hence the longest * should be listed first. */ diff --git a/src/shared/condition.c b/src/shared/condition.c index 4e5702bc41a..2d9979b9c45 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -257,7 +257,7 @@ static int condition_test_osrelease(Condition *c, char **env) { /* parse_compare_operator() needs the string to start with the comparators */ word = condition; - r = extract_first_word(&word, &key, "!<=>$", EXTRACT_RETAIN_SEPARATORS); + r = extract_first_word(&word, &key, COMPARE_OPERATOR_WITH_FNMATCH_CHARS, EXTRACT_RETAIN_SEPARATORS); if (r < 0) return log_debug_errno(r, "Failed to parse parameter: %m"); /* The os-release spec mandates env-var-like key names */ @@ -518,7 +518,7 @@ static int condition_test_firmware_smbios_field(const char *expression) { assert(expression); /* Parse SMBIOS field */ - r = extract_first_word(&expression, &field, "!<=>$", EXTRACT_RETAIN_SEPARATORS); + r = extract_first_word(&expression, &field, COMPARE_OPERATOR_WITH_FNMATCH_CHARS, EXTRACT_RETAIN_SEPARATORS); if (r < 0) return r; if (r == 0 || isempty(expression)) -- 2.47.3