<listitem><para><varname>ConditionVersion=</varname> may be used to check whether a software
version matches a certain expression, or if prefixed with the exclamation mark, does not match.
The first argument is the software whose version has to be checked. Currently
- <literal>kernel</literal> and <literal>systemd</literal> are supported. If this argument is
- omitted, <literal>kernel</literal> is implied. The second argument must be a list
- of (potentially quoted) expressions. Each expression starts with one of <literal>=</literal> or
- <literal>!=</literal> for string comparisons, <literal><</literal>, <literal><=</literal>,
+ <literal>kernel</literal>, <literal>systemd</literal> and <literal>glibc</literal> are supported.
+ If this argument is omitted, <literal>kernel</literal> is implied. The second argument must be a
+ list of (potentially quoted) expressions. Each expression starts with one of <literal>=</literal>
+ or <literal>!=</literal> for string comparisons, <literal><</literal>, <literal><=</literal>,
<literal>==</literal>, <literal><></literal>, <literal>>=</literal>,
<literal>></literal> for version comparisons, or <literal>$=</literal>, <literal>!$=</literal>
for a shell-style glob match. If no operator is specified, <literal>$=</literal> is implied.</para>
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
+#include <gnu/libc-version.h>
#include <limits.h>
#include <stdlib.h>
#include <sys/stat.h>
if (streq(word, "systemd"))
return condition_test_version_cmp(p, STRINGIFY(PROJECT_VERSION));
+ if (streq(word, "glibc"))
+ return condition_test_version_cmp(p, gnu_get_libc_version());
+
/* if no predicate has been set, default to "kernel" and use the whole parameter as condition */
if (!streq(word, "kernel"))
p = c->parameter;
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include <gnu/libc-version.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/utsname.h>
ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, v, false, false)));
ASSERT_OK_ZERO(condition_test(condition, environ));
condition_free(condition);
+
+ /* Test glibc version */
+ ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc > 1", false, false)));
+ ASSERT_OK_POSITIVE(condition_test(condition, environ));
+ condition_free(condition);
+
+ ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc < 2", false, false)));
+ ASSERT_OK_ZERO(condition_test(condition, environ));
+ condition_free(condition);
+
+ ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc < 9999", false, false)));
+ ASSERT_OK_POSITIVE(condition_test(condition, environ));
+ condition_free(condition);
+
+ ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc > 9999", false, false)));
+ ASSERT_OK_ZERO(condition_test(condition, environ));
+ condition_free(condition);
+
+ v = strjoina("glibc = ", gnu_get_libc_version());
+
+ ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, v, false, false)));
+ ASSERT_OK_POSITIVE(condition_test(condition, environ));
+ condition_free(condition);
+
+ v = strjoina("glibc != ", gnu_get_libc_version());
+
+ ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, v, false, false)));
+ ASSERT_OK_ZERO(condition_test(condition, environ));
+ condition_free(condition);
}
TEST(condition_test_credential) {