diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-12-13 20:34:13 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-12-26 17:39:44 +0100 |
commit | 5022f08a23c0b64973b74cd71be9f5122ec655a6 (patch) | |
tree | 9729b57e454b085117cb7c385311f8fd99099c27 /src/shared/condition.c | |
parent | 95f7f85d39b3a945b3ed329656e36d7b5ab51cb9 (diff) | |
download | systemd-5022f08a23c0b64973b74cd71be9f5122ec655a6.tar.gz systemd-5022f08a23c0b64973b74cd71be9f5122ec655a6.tar.bz2 systemd-5022f08a23c0b64973b74cd71be9f5122ec655a6.zip |
core,udev,networkd: add ConditionKernelVersion=
This adds a simple condition/assert/match to the service manager, to
udev's .link handling and to networkd, for matching the kernel version
string.
In this version we only do fnmatch() based globbing, but we might want
to extend that to version comparisons later on, if we like, by slightly
extending the syntax with ">=", "<=", ">", "<" and "==" expressions.
Diffstat (limited to 'src/shared/condition.c')
-rw-r--r-- | src/shared/condition.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/shared/condition.c b/src/shared/condition.c index d4bbaf3c65..887c9a7588 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -26,6 +26,7 @@ #include <string.h> #include <sys/stat.h> #include <sys/types.h> +#include <sys/utsname.h> #include <time.h> #include <unistd.h> @@ -143,6 +144,18 @@ static int condition_test_kernel_command_line(Condition *c) { return false; } +static int condition_test_kernel_version(Condition *c) { + struct utsname u; + + assert(c); + assert(c->parameter); + assert(c->type == CONDITION_KERNEL_VERSION); + + assert_se(uname(&u) >= 0); + + return fnmatch(c->parameter, u.release, 0) == 0; +} + static int condition_test_user(Condition *c) { uid_t id; int r; @@ -552,6 +565,7 @@ int condition_test(Condition *c) { [CONDITION_FILE_NOT_EMPTY] = condition_test_file_not_empty, [CONDITION_FILE_IS_EXECUTABLE] = condition_test_file_is_executable, [CONDITION_KERNEL_COMMAND_LINE] = condition_test_kernel_command_line, + [CONDITION_KERNEL_VERSION] = condition_test_kernel_version, [CONDITION_VIRTUALIZATION] = condition_test_virtualization, [CONDITION_SECURITY] = condition_test_security, [CONDITION_CAPABILITY] = condition_test_capability, @@ -612,6 +626,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = { [CONDITION_VIRTUALIZATION] = "ConditionVirtualization", [CONDITION_HOST] = "ConditionHost", [CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine", + [CONDITION_KERNEL_VERSION] = "ConditionKernelVersion", [CONDITION_SECURITY] = "ConditionSecurity", [CONDITION_CAPABILITY] = "ConditionCapability", [CONDITION_AC_POWER] = "ConditionACPower", @@ -639,6 +654,7 @@ static const char* const assert_type_table[_CONDITION_TYPE_MAX] = { [CONDITION_VIRTUALIZATION] = "AssertVirtualization", [CONDITION_HOST] = "AssertHost", [CONDITION_KERNEL_COMMAND_LINE] = "AssertKernelCommandLine", + [CONDITION_KERNEL_VERSION] = "AssertKernelVersion", [CONDITION_SECURITY] = "AssertSecurity", [CONDITION_CAPABILITY] = "AssertCapability", [CONDITION_AC_POWER] = "AssertACPower", |