]> err.no Git - systemd/commitdiff
unit: introduce ConditionFileIsExecutable= and use it where we check for a binary...
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Jul 2011 02:25:02 +0000 (04:25 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Jul 2011 02:25:02 +0000 (04:25 +0200)
TODO
man/systemd.unit.xml
src/condition.c
src/condition.h
src/load-fragment.c
units/fedora/halt-local.service
units/fedora/rc-local.service
units/suse/halt-local.service
units/suse/rc-local.service

diff --git a/TODO b/TODO
index 36a57f4b51b682e0c309427cac7533e01a2c6da9..0d6ac4130c87da6d37bd9faf4cf21a38d46f6772 100644 (file)
--- 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.
 
index f4821821518bff3c2bb498bd29a60ef17466eebe..d38a00136651b552ba94b4c513e643a5654f3a2f 100644 (file)
                                 <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>
                                 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>
index 76ee0370d22c398ef87bcad6331220ea16c0b8ff..f9202f68508d9aafd12e53f14e9781f00a332e46 100644 (file)
@@ -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;
 
index ff896a793a888a6ea953feda956c258eec38124e..672996e83635ce18dad03fb2ecba311d55a33a38 100644 (file)
@@ -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,
index 05e60bf8fdee973d883b2754c94a1172d00155ff..5c1dff60b8aba1f029755b17579b4fc951842c65 100644 (file)
@@ -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"    },
index 79f8f12b7d2097bcb28d874801247e88a49d15f7..a9f6feb32058b8922bd15a9bdc7b462f02f5d80a 100644 (file)
@@ -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
index 8c0b2004944acb6b02913862c221d2d601439322..f5f940f7ee41dcafc64eb361f25437b87a86ecca 100644 (file)
@@ -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
index 68cacc6658a031989bb337e393ddbdc3f7699a35..796012c0c4c181680fbf8b278dd3740dd923d45b 100644 (file)
@@ -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
index 38884c5cd38cf4a9e015ff1eef98c88387ebd341..fe4c00716eabf26d1053e32306e0b0762bcc6279 100644 (file)
@@ -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