Commit Graph
15 Commits
Author SHA1 Message Date
Matteo Croce 854711645b use FOREACH_ELEMENT
Use FOREACH_ELEMENT where possible. Generated with this command,
and checked manually:

    git grep -l 'FOREACH_ARRAY.*ELEMENTSOF' | \
    xargs sed -ri 's/FOREACH_ARRAY\((.*), (.*), (ELEMENTSOF.*)\)/FOREACH_ELEMENT(\1, \2)/'
2024-04-18 17:39:34 +02:00
Mike Yuan 38617c516a various: use FOREACH_ARRAY more
Prompted by #30622
2023-12-25 20:17:48 +09:00
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Yu Watanabe 8ced74d76b compare: fix typo 2023-07-15 05:11:30 +09:00
Lennart Poettering 71a3ff036b 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-*
2022-09-01 23:16:13 +02:00
Lennart Poettering 5f6b2d394b compare: propagate errors of fnmatch() as errors 2022-09-01 23:16:13 +02:00
Lennart Poettering 2e8fa6274d compare: support textual operators, and port analyze over to it 2022-09-01 23:16:13 +02:00
Lennart Poettering 6061c86693 compare: add two new operators "==" and "<>"
These two operators always indicate ordering comparisons, as opposed to
"=" and "!=" which depending on context mean literal string compares.

This is useful for ConditionOSRelease= for example, as this means
there's now always a way to do version compares.
2022-09-01 23:16:13 +02:00
Lennart Poettering 38c09fa008 compare: rework table in parse_compare_operator() to be array of structs
Let's change the lookup table to contain pairs of operator/strings,
instead of being indexed by operator.

The table isn't dense anymore, and this allows us to add alias strings
sooner or later.
2022-09-01 23:16:10 +02:00
Lennart Poettering 57610982f7 compare: add flag for parse_compare_operator() to do equality/inequality comparison via simple string compares
This allows us to switch condition_test_osrelease() to use generic
version_or_fnmatch_compare() for executing the comparison.
2022-09-01 23:15:14 +02:00
Lennart Poettering 69f0a6091b compare: add a proper flags field for parse_compare_operator() 2022-09-01 23:15:14 +02:00
Lennart Poettering 97c7bed90a compare: drop use of FNM_EXTMATCH for now
None of our other fnmatch() calls make use of this, and the concept was
new to me at least. Given that this is only used for the recently added
SMBIOS field matches (and is not included in any release) let's disable
"extended" matches for now. We can certainly revisit this, and enable it
later if there is real demand, but if we do, we should probably add that
all over the place, not just for smbios matches.
2022-09-01 23:15:14 +02:00
Lennart Poettering 8bd2cf6e11 comapre: add generic implementation for comapring with verscmp+fnmatch 2022-09-01 23:15:14 +02:00
Lennart Poettering 650c4c8707 compare: move test_order() → compare-operator.[ch] 2022-09-01 23:15:14 +02:00
Lennart Poettering a8835c1190 condition: split out order operator enum
Let's move the operator enum into its own .c/.h file, so that we can
reuse it elsewhere, in particular systemd-analyze's compare-versions
logic.

Let's rename the concept CompareOperator, since it is nowadays
genericlaly about both order *and* fnmatch comparisons, hence just
naming it "order" is misleading.
2022-09-01 23:12:34 +02:00