chiark / gitweb /
condition: fix reversed tests if path does not exist at all
[elogind.git] / src / condition.c
index 7f8564966a22cdc39dcce79eaa693c445da9d2f3..1438ea85a0c52ed25e82969e16fbd3470e7a1aa0 100644 (file)
@@ -163,10 +163,18 @@ bool condition_test(Condition *c) {
                 struct stat st;
 
                 if (stat(c->parameter, &st) < 0)
-                        return !c->negate;
+                        return c->negate;
                 return S_ISDIR(st.st_mode) == !c->negate;
         }
 
+        case CONDITION_PATH_IS_SYMBOLIC_LINK: {
+                struct stat st;
+
+                if (lstat(c->parameter, &st) < 0)
+                        return c->negate;
+                return S_ISLNK(st.st_mode) == !c->negate;
+        }
+
         case CONDITION_PATH_IS_MOUNT_POINT:
                 return (path_is_mount_point(c->parameter, true) > 0) == !c->negate;
 
@@ -181,7 +189,7 @@ bool condition_test(Condition *c) {
                 struct stat st;
 
                 if (stat(c->parameter, &st) < 0)
-                        return !c->negate;
+                        return c->negate;
 
                 return (S_ISREG(st.st_mode) && (st.st_mode & 0111)) == !c->negate;
         }
@@ -256,6 +264,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = {
         [CONDITION_PATH_EXISTS] = "ConditionPathExists",
         [CONDITION_PATH_EXISTS_GLOB] = "ConditionPathExistsGlob",
         [CONDITION_PATH_IS_DIRECTORY] = "ConditionPathIsDirectory",
+        [CONDITION_PATH_IS_SYMBOLIC_LINK] = "ConditionPathIsSymbolicLink",
         [CONDITION_PATH_IS_MOUNT_POINT] = "ConditionPathIsMountPoint",
         [CONDITION_DIRECTORY_NOT_EMPTY] = "ConditionDirectoryNotEmpty",
         [CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine",