From 9cbf12820271eca60380c1dd6ee0027782eb45e8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 10 Aug 2021 14:50:54 +0200 Subject: [PATCH] core: don't go to disk for masked unit state if we know it anyway 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/unit.c b/src/core/unit.c index 8ce94ccb75..5cc66ab164 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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; -- 2.25.1