]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
compare: add macro for operator charset
authorLennart Poettering <lennart@poettering.net>
Mon, 29 Aug 2022 09:09:48 +0000 (11:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 1 Sep 2022 21:16:13 +0000 (23:16 +0200)
src/shared/compare-operator.h
src/shared/condition.c

index db5c2f0cfc92b14d061472382bc0be1e069fe9e2..900f3e54b20facc991529eb8e1c3f05cefd67fd2 100644 (file)
@@ -4,6 +4,9 @@
 #include <errno.h>
 #include <stdbool.h>
 
+#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. */
index 4e5702bc41aea822cb8aefb2db4db6d2c130f582..2d9979b9c45ff0809ae30045fe125d63ddf334e8 100644 (file)
@@ -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))