]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/condition.c
treewide: fix typos and then/that use
[thirdparty/systemd.git] / src / shared / condition.c
index da7560f05fb616f2176f7c2a389bb61b8a2591e1..3a45ed265c6ec0996a48859b6e18a9e42e8910b4 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdlib.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <fnmatch.h>
+#include <limits.h>
+#include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <time.h>
 #include <unistd.h>
-#include <sys/statvfs.h>
-#include <fnmatch.h>
 
 #include "sd-id128.h"
-#include "util.h"
-#include "virt.h"
-#include "path-util.h"
-#include "fileio.h"
-#include "architecture.h"
-#include "smack-util.h"
+
+#include "alloc-util.h"
 #include "apparmor-util.h"
+#include "architecture.h"
+#include "audit-util.h"
+#include "cap-list.h"
+#include "condition.h"
+#include "extract-word.h"
+#include "fd-util.h"
+#include "glob-util.h"
+#include "hostname-util.h"
 #include "ima-util.h"
+#include "list.h"
+#include "macro.h"
+#include "mount-util.h"
+#include "parse-util.h"
+#include "path-util.h"
+#include "proc-cmdline.h"
 #include "selinux-util.h"
-#include "audit.h"
-#include "condition.h"
-#include "cap-list.h"
+#include "smack-util.h"
+#include "stat-util.h"
+#include "string-table.h"
+#include "string-util.h"
+#include "util.h"
+#include "virt.h"
 
 Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) {
         Condition *c;
@@ -46,7 +60,7 @@ Condition* condition_new(ConditionType type, const char *parameter, bool trigger
 
         assert(type >= 0);
         assert(type < _CONDITION_TYPE_MAX);
-        assert(!parameter == (type == CONDITION_NULL));
+        assert((!parameter) == (type == CONDITION_NULL));
 
         c = new0(Condition, 1);
         if (!c)
@@ -102,7 +116,7 @@ static int condition_test_kernel_command_line(Condition *c) {
                 _cleanup_free_ char *word = NULL;
                 bool found;
 
-                r = unquote_first_word(&p, &word, true);
+                r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
                 if (r < 0)
                         return r;
                 if (r == 0)
@@ -126,13 +140,12 @@ static int condition_test_kernel_command_line(Condition *c) {
 
 static int condition_test_virtualization(Condition *c) {
         int b, v;
-        const char *id;
 
         assert(c);
         assert(c->parameter);
         assert(c->type == CONDITION_VIRTUALIZATION);
 
-        v = detect_virtualization(&id);
+        v = detect_virtualization();
         if (v < 0)
                 return v;
 
@@ -146,14 +159,14 @@ static int condition_test_virtualization(Condition *c) {
                 return true;
 
         /* Then, compare categorization */
-        if (v == VIRTUALIZATION_VM && streq(c->parameter, "vm"))
+        if (VIRTUALIZATION_IS_VM(v) && streq(c->parameter, "vm"))
                 return true;
 
-        if (v == VIRTUALIZATION_CONTAINER && streq(c->parameter, "container"))
+        if (VIRTUALIZATION_IS_CONTAINER(v) && streq(c->parameter, "container"))
                 return true;
 
         /* Finally compare id */
-        return v > 0 && streq(c->parameter, id);
+        return v != VIRTUALIZATION_NONE && streq(c->parameter, virtualization_to_string(v));
 }
 
 static int condition_test_architecture(Condition *c) {
@@ -222,7 +235,7 @@ static int condition_test_security(Condition *c) {
         assert(c->type == CONDITION_SECURITY);
 
         if (streq(c->parameter, "selinux"))
-                return mac_selinux_use();
+                return mac_selinux_have();
         if (streq(c->parameter, "smack"))
                 return mac_smack_use();
         if (streq(c->parameter, "apparmor"))
@@ -282,7 +295,7 @@ static int condition_test_needs_update(Condition *c) {
                 return false;
 
         /* Any other failure means we should allow the condition to be true,
-         * so that we rather invoke too many update tools then too
+         * so that we rather invoke too many update tools than too
          * few. */
 
         if (!path_is_absolute(c->parameter))
@@ -350,7 +363,7 @@ static int condition_test_path_is_mount_point(Condition *c) {
         assert(c->parameter);
         assert(c->type == CONDITION_PATH_IS_MOUNT_POINT);
 
-        return path_is_mount_point(c->parameter, true) > 0;
+        return path_is_mount_point(c->parameter, AT_SYMLINK_FOLLOW) > 0;
 }
 
 static int condition_test_path_is_read_write(Condition *c) {