summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-07-12 04:25:02 +0200
committerLennart Poettering <lennart@poettering.net>2011-07-12 04:25:02 +0200
commit82e487c56d0947796793b6fd2836264328defe9f (patch)
tree2dfd5d979d064c7bc116cfca28ea1e1df65eac70
parent3611581ebdabbe3a1d6a9b5310a0b59792279d7d (diff)
unit: introduce ConditionFileIsExecutable= and use it where we check for a binary we'll spawn
-rw-r--r--TODO2
-rw-r--r--man/systemd.unit.xml9
-rw-r--r--src/condition.c9
-rw-r--r--src/condition.h1
-rw-r--r--src/load-fragment.c1
-rw-r--r--units/fedora/halt-local.service2
-rw-r--r--units/fedora/rc-local.service2
-rw-r--r--units/suse/halt-local.service2
-rw-r--r--units/suse/rc-local.service2
9 files changed, 23 insertions, 7 deletions
diff --git a/TODO b/TODO
index 36a57f4b51..0d6ac4130c 100644
--- a/TODO
+++ b/TODO
@@ -26,8 +26,6 @@ Features:
* possibly apply systemd-sysctl per network device subtrees on hotplug
-* add conditions for file executability
-
* implement Register= switch in .socket units to enable registration
in Avahi, RPC and other socket registration services.
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index f482182151..d38a001366 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -610,6 +610,7 @@
<term><varname>ConditionPathExistsGlob=</varname></term>
<term><varname>ConditionPathIsDirectory=</varname></term>
<term><varname>ConditionDirectoryNotEmpty=</varname></term>
+ <term><varname>ConditionFileIsExecutable=</varname></term>
<term><varname>ConditionKernelCommandLine=</varname></term>
<term><varname>ConditionVirtualization=</varname></term>
<term><varname>ConditionSecurity=</varname></term>
@@ -642,7 +643,13 @@
is similar to
<varname>ConditionPathExists=</varname>
but verifies whether a certain path
- exists and is a directory.
+ exists and is a
+ directory. <varname>ConditionFileIsExecutable=</varname>
+ is similar to
+ <varname>ConditionPathExists=</varname>
+ but verifies whether a certain path
+ exists, is a regular file and marked
+ executable.
<varname>ConditionDirectoryNotEmpty=</varname>
is similar to
<varname>ConditionPathExists=</varname>
diff --git a/src/condition.c b/src/condition.c
index 76ee0370d2..f9202f6850 100644
--- a/src/condition.c
+++ b/src/condition.c
@@ -168,6 +168,15 @@ bool condition_test(Condition *c) {
return !(k == -ENOENT || k > 0) == !c->negate;
}
+ case CONDITION_FILE_IS_EXECUTABLE: {
+ struct stat st;
+
+ if (lstat(c->parameter, &st) < 0)
+ return !c->negate;
+
+ return (S_ISREG(st.st_mode) && (st.st_mode & 0111)) == !c->negate;
+ }
+
case CONDITION_KERNEL_COMMAND_LINE:
return test_kernel_command_line(c->parameter) == !c->negate;
diff --git a/src/condition.h b/src/condition.h
index ff896a793a..672996e836 100644
--- a/src/condition.h
+++ b/src/condition.h
@@ -31,6 +31,7 @@ typedef enum ConditionType {
CONDITION_PATH_EXISTS_GLOB,
CONDITION_PATH_IS_DIRECTORY,
CONDITION_DIRECTORY_NOT_EMPTY,
+ CONDITION_FILE_IS_EXECUTABLE,
CONDITION_KERNEL_COMMAND_LINE,
CONDITION_VIRTUALIZATION,
CONDITION_SECURITY,
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 05e60bf8fd..5c1dff60b8 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -2003,6 +2003,7 @@ static int load_from_path(Unit *u, const char *path) {
{ "ConditionPathExistsGlob", config_parse_condition_path, CONDITION_PATH_EXISTS_GLOB, u, "Unit" },
{ "ConditionPathIsDirectory", config_parse_condition_path, CONDITION_PATH_IS_DIRECTORY, u, "Unit" },
{ "ConditionDirectoryNotEmpty", config_parse_condition_path, CONDITION_DIRECTORY_NOT_EMPTY, u, "Unit" },
+ { "ConditionFileIsExecutable", config_parse_condition_path, CONDITION_FILE_IS_EXECUTABLE, u, "Unit" },
{ "ConditionKernelCommandLine", config_parse_condition_string, CONDITION_KERNEL_COMMAND_LINE, u, "Unit" },
{ "ConditionVirtualization", config_parse_condition_string, CONDITION_VIRTUALIZATION, u, "Unit" },
{ "ConditionSecurity", config_parse_condition_string, CONDITION_SECURITY, u, "Unit" },
diff --git a/units/fedora/halt-local.service b/units/fedora/halt-local.service
index 79f8f12b7d..a9f6feb320 100644
--- a/units/fedora/halt-local.service
+++ b/units/fedora/halt-local.service
@@ -7,7 +7,7 @@
[Unit]
Description=/sbin/halt.local Compatibility
-ConditionPathExists=/sbin/halt.local
+ConditionFileIsExecutable=/sbin/halt.local
DefaultDependencies=no
After=shutdown.target
Before=final.target
diff --git a/units/fedora/rc-local.service b/units/fedora/rc-local.service
index 8c0b200494..f5f940f7ee 100644
--- a/units/fedora/rc-local.service
+++ b/units/fedora/rc-local.service
@@ -7,7 +7,7 @@
[Unit]
Description=/etc/rc.local Compatibility
-ConditionPathExists=/etc/rc.d/rc.local
+ConditionFileIsExecutable=/etc/rc.d/rc.local
[Service]
Type=forking
diff --git a/units/suse/halt-local.service b/units/suse/halt-local.service
index 68cacc6658..796012c0c4 100644
--- a/units/suse/halt-local.service
+++ b/units/suse/halt-local.service
@@ -7,7 +7,7 @@
[Unit]
Description=/etc/init.d/halt.local Compatibility
-ConditionPathExists=/etc/init.d/halt.local
+ConditionFileIsExecutable=/etc/init.d/halt.local
DefaultDependencies=no
After=shutdown.target
Before=final.target
diff --git a/units/suse/rc-local.service b/units/suse/rc-local.service
index 38884c5cd3..fe4c00716e 100644
--- a/units/suse/rc-local.service
+++ b/units/suse/rc-local.service
@@ -7,7 +7,7 @@
[Unit]
Description=/etc/init.d/boot.local Compatibility
-ConditionPathExists=/etc/init.d/boot.local
+ConditionFileIsExecutable=/etc/init.d/boot.local
[Service]
Type=oneshot