chiark / gitweb /
unit: introduce ConditionPathIsReadWrite
authorLennart Poettering <lennart@poettering.net>
Thu, 12 Apr 2012 00:39:02 +0000 (02:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 12 Apr 2012 10:58:19 +0000 (12:58 +0200)
man/systemd.unit.xml
src/core/condition.c
src/core/condition.h
src/load-fragment-gperf.gperf.m4

index 3fc7f78198941ab937143e0553fad9eed3d333d0..28ca8cef105fea522241d18e37a09f92b7dc59b7 100644 (file)
                                 <term><varname>ConditionPathIsDirectory=</varname></term>
                                 <term><varname>ConditionPathIsSymbolicLink=</varname></term>
                                 <term><varname>ConditionPathIsMountPoint=</varname></term>
+                                <term><varname>ConditionPathIsReadWrite=</varname></term>
                                 <term><varname>ConditionDirectoryNotEmpty=</varname></term>
                                 <term><varname>ConditionFileIsExecutable=</varname></term>
                                 <term><varname>ConditionKernelCommandLine=</varname></term>
                                 <varname>ConditionPathExists=</varname>
                                 but verifies whether a certain path
                                 exists and is a mount
-                                point. <varname>ConditionFileIsExecutable=</varname>
+                                point. <varname>ConditionPathIsReadWrite=</varname>
+                                is similar to
+                                <varname>ConditionPathExists=</varname>
+                                but verifies whether the underlying
+                                file system is read and writable
+                                (i.e. not mounted
+                                read-only). <varname>ConditionFileIsExecutable=</varname>
                                 is similar to
                                 <varname>ConditionPathExists=</varname>
                                 but verifies whether a certain path
                                 <varname>openvz</varname>,
                                 <varname>lxc</varname>,
                                 <varname>lxc-libvirt</varname>,
-                                <varname>systemd-nspawn</varname> to test
-                                against a specific implementation. If
-                                multiple virtualization technologies
-                                are nested only the innermost is
-                                considered. The test may be negated by
-                                prepending an exclamation mark.
+                                <varname>systemd-nspawn</varname> to
+                                test against a specific
+                                implementation. If multiple
+                                virtualization technologies are nested
+                                only the innermost is considered. The
+                                test may be negated by prepending an
+                                exclamation mark.
                                 <varname>ConditionSecurity=</varname>
                                 may be used to check whether the given
                                 security module is enabled on the
index 5dad5248bbac8bbcb2068493e8d6b4263d16725d..3b246f1a64ed479fee757439abf60940617ebd25 100644 (file)
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/capability.h>
+#include <sys/statvfs.h>
 
 #ifdef HAVE_SELINUX
 #include <selinux/selinux.h>
@@ -222,6 +223,15 @@ bool condition_test(Condition *c) {
         case CONDITION_PATH_IS_MOUNT_POINT:
                 return (path_is_mount_point(c->parameter, true) > 0) == !c->negate;
 
+        case CONDITION_PATH_IS_READ_WRITE: {
+                struct statvfs st;
+
+                if (statvfs(c->parameter, &st) < 0)
+                        return c->negate;
+
+                return !(st.f_flag & ST_RDONLY) == !c->negate;
+        }
+
         case CONDITION_DIRECTORY_NOT_EMPTY: {
                 int k;
 
@@ -313,6 +323,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = {
         [CONDITION_PATH_IS_DIRECTORY] = "ConditionPathIsDirectory",
         [CONDITION_PATH_IS_SYMBOLIC_LINK] = "ConditionPathIsSymbolicLink",
         [CONDITION_PATH_IS_MOUNT_POINT] = "ConditionPathIsMountPoint",
+        [CONDITION_PATH_IS_READ_WRITE] = "ConditionPathIsReadWrite",
         [CONDITION_DIRECTORY_NOT_EMPTY] = "ConditionDirectoryNotEmpty",
         [CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine",
         [CONDITION_VIRTUALIZATION] = "ConditionVirtualization",
index 2a44ba681f0e3b33a0be9128e364cc05cb1403b2..2d1f2cd17e57c28f5f6b5c9d3c3b87ea0264d650 100644 (file)
@@ -32,6 +32,7 @@ typedef enum ConditionType {
         CONDITION_PATH_IS_DIRECTORY,
         CONDITION_PATH_IS_SYMBOLIC_LINK,
         CONDITION_PATH_IS_MOUNT_POINT,
+        CONDITION_PATH_IS_READ_WRITE,
         CONDITION_DIRECTORY_NOT_EMPTY,
         CONDITION_FILE_IS_EXECUTABLE,
         CONDITION_KERNEL_COMMAND_LINE,
index 4b02e3157ef68dc851ed20b490e68d79ff30a63e..c65db30fff8b96ee39c370ddeb640be8ec6cf43f 100644 (file)
@@ -118,6 +118,7 @@ Unit.ConditionPathExistsGlob,    config_parse_unit_condition_path,   CONDITION_P
 Unit.ConditionPathIsDirectory,   config_parse_unit_condition_path,   CONDITION_PATH_IS_DIRECTORY,   0
 Unit.ConditionPathIsSymbolicLink,config_parse_unit_condition_path,   CONDITION_PATH_IS_SYMBOLIC_LINK,0
 Unit.ConditionPathIsMountPoint,  config_parse_unit_condition_path,   CONDITION_PATH_IS_MOUNT_POINT, 0
+Unit.ConditionPathIsReadWrite,   config_parse_unit_condition_path,   CONDITION_PATH_IS_READ_WRITE,  0
 Unit.ConditionDirectoryNotEmpty, config_parse_unit_condition_path,   CONDITION_DIRECTORY_NOT_EMPTY, 0
 Unit.ConditionFileIsExecutable,  config_parse_unit_condition_path,   CONDITION_FILE_IS_EXECUTABLE,  0
 Unit.ConditionKernelCommandLine, config_parse_unit_condition_string, CONDITION_KERNEL_COMMAND_LINE, 0