diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-08-29 13:42:44 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-09-01 23:16:13 +0200 |
commit | 71a3ff036be64cd9c4f66c02598be58666a1d132 (patch) | |
tree | 0305f8bc88d0c7be5695f199b1e61b017eb8c703 /src/shared/compare-operator.c | |
parent | condition: change ConditionKernelVersion= so that =/!= mean literal string co... (diff) | |
download | systemd-71a3ff036be64cd9c4f66c02598be58666a1d132.tar.xz systemd-71a3ff036be64cd9c4f66c02598be58666a1d132.zip |
condition: change operator logic to use $= instead of =$ for glob comparisons
So this is a bit of a bikeshedding thing. But I think we should do this
nonetheless, before this is released.
Playing around with the glob matches I realized that "=$" is really hard
to grep for, since in shell code it's an often seen construct. Also,
when reading code I often found myself thinking first that the "$"
belongs to the rvalue instead of the operator, in a variable expansion
scheme.
If we move the $ character to the left hand, I think we are on the safer
side, since usually lvalues are much more restricted in character sets
than rvalues (at least most programming languages do enforce limits on
the character set for identifiers).
It makes it much easier to grep for the new operator, and easier to read
too. Example:
before:
ConditionOSRelease=ID=$fedora-*
after:
ConditionOSRelease=ID$=fedora-*
Diffstat (limited to 'src/shared/compare-operator.c')
-rw-r--r-- | src/shared/compare-operator.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/shared/compare-operator.c b/src/shared/compare-operator.c index e9c7cc9b2b..ad931b778f 100644 --- a/src/shared/compare-operator.c +++ b/src/shared/compare-operator.c @@ -12,8 +12,8 @@ CompareOperator parse_compare_operator(const char **s, CompareOperatorParseFlags CompareOperatorParseFlags valid_mask; /* If this operator appears when flags in mask not set, fail */ CompareOperatorParseFlags need_mask; /* Skip over this operattor when flags in mask not set */ } table[] = { - { COMPARE_FNMATCH_EQUAL, "=$", .valid_mask = COMPARE_ALLOW_FNMATCH }, - { COMPARE_FNMATCH_UNEQUAL, "!=$", .valid_mask = COMPARE_ALLOW_FNMATCH }, + { COMPARE_FNMATCH_EQUAL, "$=", .valid_mask = COMPARE_ALLOW_FNMATCH }, + { COMPARE_FNMATCH_UNEQUAL, "!$=", .valid_mask = COMPARE_ALLOW_FNMATCH }, { COMPARE_UNEQUAL, "<>" }, { COMPARE_LOWER_OR_EQUAL, "<=" }, |