chiark / gitweb /
src: our lord is coverity
[elogind.git] / src / condition.c
index 1d6cf12ad4b71c46086d5791cd45d5bebd4d4de0..b404b49c925eba8c92a6a97420d0829c148c6c3a 100644 (file)
@@ -30,7 +30,9 @@
 Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) {
         Condition *c;
 
-        c = new0(Condition, 1);
+        if (!(c = new0(Condition, 1)))
+                return NULL;
+
         c->type = type;
         c->trigger = trigger;
         c->negate = negate;
@@ -67,6 +69,9 @@ static bool test_kernel_command_line(const char *parameter) {
 
         assert(parameter);
 
+        if (detect_virtualization(NULL) > 0)
+                return false;
+
         if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) {
                 log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
                 return false;
@@ -131,6 +136,14 @@ bool condition_test(Condition *c) {
         case CONDITION_PATH_EXISTS:
                 return (access(c->parameter, F_OK) >= 0) == !c->negate;
 
+        case CONDITION_PATH_IS_DIRECTORY: {
+                struct stat st;
+
+                if (lstat(c->parameter, &st) < 0)
+                        return !c->negate;
+                return S_ISDIR(st.st_mode) == !c->negate;
+        }
+
         case CONDITION_DIRECTORY_NOT_EMPTY: {
                 int k;