]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: don't go to disk for masked unit state if we know it anyway
authorLennart Poettering <lennart@poettering.net>
Tue, 10 Aug 2021 12:50:54 +0000 (14:50 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 10 Aug 2021 19:30:41 +0000 (20:30 +0100)
This should speed up our selinux checks a bit, since in most cases we
already know if a unit is masked, so use that info.

src/core/unit.c

index 8ce94ccb75e641c216e936dde611fcedad15781e..5cc66ab164f2d9493baa2b506833ea667e152b82 100644 (file)
@@ -5497,10 +5497,19 @@ const char *unit_label_path(const Unit *u) {
         /* Returns the file system path to use for MAC access decisions, i.e. the file to read the SELinux label off
          * when validating access checks. */
 
+        if (IN_SET(u->load_state, UNIT_MASKED, UNIT_NOT_FOUND, UNIT_MERGED))
+                return NULL; /* Shortcut things if we know there is no real, relevant unit file around */
+
         p = u->source_path ?: u->fragment_path;
         if (!p)
                 return NULL;
 
+        if (IN_SET(u->load_state, UNIT_LOADED, UNIT_BAD_SETTING, UNIT_ERROR))
+                return p; /* Shortcut things, if we successfully loaded at least some stuff from the unit file */
+
+        /* Not loaded yet, we need to go to disk */
+        assert(u->load_state == UNIT_STUB);
+
         /* If a unit is masked, then don't read the SELinux label of /dev/null, as that really makes no sense */
         if (null_or_empty_path(p) > 0)
                 return NULL;