]> err.no Git - systemd/commitdiff
unit: introduce ConditionDirectoryNotEmpty=
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Nov 2010 19:06:49 +0000 (20:06 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 15 Nov 2010 21:13:25 +0000 (22:13 +0100)
man/systemd.unit.xml
src/condition.c
src/condition.h
src/load-fragment.c
src/path.c

index 39862cf7c89162e510f1bb35eb820c1aa47f5851..b29473afa3bb9862e24093398fc99741836eafb7 100644 (file)
 
                         <varlistentry>
                                 <term><varname>ConditionPathExists=</varname></term>
+                                <term><varname>ConditionDirectoryNotEmpty=</varname></term>
                                 <term><varname>ConditionKernelCommandLine=</varname></term>
                                 <term><varname>ConditionNull=</varname></term>
 
                                 is prefixed with an exclamation mark
                                 (!), the test is negated, and the unit
                                 only started if the path does not
-                                exist. Similarly
+                                exist. <varname>ConditionDirectoryNotEmpty=</varname>
+                                is similar to
+                                <varname>ConditionPathExists=</varname>
+                                but verifies whether a cetrain path is
+                                exists and is a non-empty
+                                directory. Similarly
                                 <varname>ConditionKernelCommandLine=</varname>
                                 may be used to check whether a
                                 specific kernel command line option is
index 4bbd4dbafaecfe1f53b11133db75255dfd297e76..21da2eb9e94c032778064b3283904ba1532ad5cf 100644 (file)
@@ -106,6 +106,13 @@ bool condition_test(Condition *c) {
         case CONDITION_PATH_EXISTS:
                 return (access(c->parameter, F_OK) >= 0) == !c->negate;
 
+        case CONDITION_DIRECTORY_NOT_EMPTY: {
+                int k;
+
+                k = dir_is_empty(c->parameter);
+                return !(k == -ENOENT || k > 0) == !c->negate;
+        }
+
         case CONDITION_KERNEL_COMMAND_LINE:
                 return !!test_kernel_command_line(c->parameter) == !c->negate;
 
index b9d3f34aefb07642f5f92e1ac57a5241abd3589e..2f2689cc6da7b879cc8a500fbab70c6f360b71b0 100644 (file)
@@ -28,6 +28,7 @@
 
 typedef enum ConditionType {
         CONDITION_PATH_EXISTS,
+        CONDITION_DIRECTORY_NOT_EMPTY,
         CONDITION_KERNEL_COMMAND_LINE,
         CONDITION_NULL,
         _CONDITION_TYPE_MAX,
index 9b39d9161af1efbf0504587cad0496b674117de8..1b23205a2f7fde8eb66842824678a8219ff05269 100644 (file)
@@ -1448,7 +1448,8 @@ static int config_parse_condition_path(
                 return 0;
         }
 
-        if (!(c = condition_new(CONDITION_PATH_EXISTS, rvalue, negate)))
+        if (!(c = condition_new(streq(lvalue, "ConditionPathExists") ? CONDITION_PATH_EXISTS : CONDITION_DIRECTORY_NOT_EMPTY,
+                                rvalue, negate)))
                 return -ENOMEM;
 
         LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
@@ -1815,6 +1816,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "DefaultDependencies",    config_parse_bool,            &u->meta.default_dependencies,                   "Unit"    },
                 { "JobTimeoutSec",          config_parse_usec,            &u->meta.job_timeout,                            "Unit"    },
                 { "ConditionPathExists",    config_parse_condition_path,  u,                                               "Unit"    },
+                { "ConditionDirectoryNotEmpty", config_parse_condition_path,  u,                                           "Unit"    },
                 { "ConditionKernelCommandLine", config_parse_condition_kernel, u,                                          "Unit"    },
                 { "ConditionNull",          config_parse_condition_null,  u,                                               "Unit"    },
 
index f4a0a288bb0708c9142f34f1a8c64ce1e1fcde59..a8b10724495b6198d246d269122c44f1168f8304 100644 (file)
@@ -355,9 +355,13 @@ static void path_enter_waiting(Path *p, bool initial, bool recheck) {
                         good = access(s->path, F_OK) >= 0;
                         break;
 
-                case PATH_DIRECTORY_NOT_EMPTY:
-                        good = dir_is_empty(s->path) == 0;
+                case PATH_DIRECTORY_NOT_EMPTY: {
+                        int k;
+
+                        k = dir_is_empty(s->path);
+                        good = !(k == -ENOENT || k > 0);
                         break;
+                }
 
                 case PATH_CHANGED: {
                         bool b;