[systemd-devel] [PATCH] condition: add option ConditionArchitecture
Lukas Nykryn
lnykryn at redhat.com
Tue Mar 26 10:38:00 PDT 2013
---
TODO | 2 --
man/systemd.unit.xml.in | 8 ++++++++
src/core/condition.c | 16 ++++++++++++++++
src/core/condition.h | 1 +
src/core/load-fragment-gperf.gperf.m4 | 1 +
5 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/TODO b/TODO
index b49d3e1..5ef260d 100644
--- a/TODO
+++ b/TODO
@@ -62,8 +62,6 @@ Features:
need another AND level in the expressions,
i.e. sd_journal_add_conjunction().
-* add ConditionArchitecture= or so
-
* teach ConditionKernelCommandLine= globs or regexes (in order to match foobar={no,0,off})
* hostnamectl: when a passed pretty hostname also qualifies as low-level name, then only set low-level name, and unset the pretty hostname
diff --git a/man/systemd.unit.xml.in b/man/systemd.unit.xml.in
index e99703f..ba42826 100644
--- a/man/systemd.unit.xml.in
+++ b/man/systemd.unit.xml.in
@@ -873,6 +873,7 @@
<term><varname>ConditionCapability=</varname></term>
<term><varname>ConditionHost=</varname></term>
<term><varname>ConditionACPower=</varname></term>
+ <term><varname>ConditionArchitecture=</varname></term>
<term><varname>ConditionNull=</varname></term>
<listitem><para>Before starting a unit
@@ -1059,6 +1060,13 @@
all AC connectors are disconnected
from a power source.</para>
+ <para><varname>ConditionArchitecture=</varname>
+ may be used to check system architecture.
+ Given value is compared against utsname.machine
+ returned by
+ <citerefentry><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry>.
+ </para>
+
<para>Finally,
<varname>ConditionNull=</varname> may
be used to add a constant condition
diff --git a/src/core/condition.c b/src/core/condition.c
index 30199c1..4f6a3e5 100644
--- a/src/core/condition.c
+++ b/src/core/condition.c
@@ -26,6 +26,7 @@
#include <sys/capability.h>
#include <sys/statvfs.h>
#include <fnmatch.h>
+#include <sys/utsname.h>
#ifdef HAVE_SELINUX
#include <selinux/selinux.h>
@@ -232,6 +233,17 @@ static bool test_ac_power(const char *parameter) {
return (on_ac_power() != 0) == !!r;
}
+static bool test_architecture(const char* parameter) {
+ struct utsname buf;
+
+ if (uname(&buf) < 0) {
+ log_warning("Failed to call uname: %s", strerror(errno));
+ return false;
+ }
+
+ return streq(buf.machine, parameter);
+}
+
bool condition_test(Condition *c) {
assert(c);
@@ -311,6 +323,9 @@ bool condition_test(Condition *c) {
case CONDITION_NULL:
return !c->negate;
+ case CONDITION_ARCHITECTURE:
+ return test_architecture(c->parameter) == !c->negate;
+
default:
assert_not_reached("Invalid condition type.");
}
@@ -379,6 +394,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = {
[CONDITION_SECURITY] = "ConditionSecurity",
[CONDITION_HOST] = "ConditionHost",
[CONDITION_AC_POWER] = "ConditionACPower",
+ [CONDITION_ARCHITECTURE] = "ConditionArchitecture",
[CONDITION_NULL] = "ConditionNull"
};
diff --git a/src/core/condition.h b/src/core/condition.h
index 1797385..3583bad 100644
--- a/src/core/condition.h
+++ b/src/core/condition.h
@@ -41,6 +41,7 @@ typedef enum ConditionType {
CONDITION_CAPABILITY,
CONDITION_HOST,
CONDITION_AC_POWER,
+ CONDITION_ARCHITECTURE,
CONDITION_NULL,
_CONDITION_TYPE_MAX,
_CONDITION_TYPE_INVALID = -1
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
index 3643bcd..2cc792b 100644
--- a/src/core/load-fragment-gperf.gperf.m4
+++ b/src/core/load-fragment-gperf.gperf.m4
@@ -138,6 +138,7 @@ Unit.ConditionSecurity, config_parse_unit_condition_string, CONDITION_S
Unit.ConditionCapability, config_parse_unit_condition_string, CONDITION_CAPABILITY, 0
Unit.ConditionHost, config_parse_unit_condition_string, CONDITION_HOST, 0
Unit.ConditionACPower, config_parse_unit_condition_string, CONDITION_AC_POWER, 0
+Unit.ConditionArchitecture, config_parse_unit_condition_string, CONDITION_ARCHITECTURE, 0
Unit.ConditionNull, config_parse_unit_condition_null, 0, 0
m4_dnl
Service.PIDFile, config_parse_unit_path_printf, 0, offsetof(Service, pid_file)
--
1.8.1.4
More information about the systemd-devel
mailing list