]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: ignore dropins for masked units completely when checking need_reload 33711/head
authorMike Yuan <me@yhndnzj.com>
Mon, 8 Jul 2024 15:12:20 +0000 (17:12 +0200)
committerDavid Tardon <dtardon@redhat.com>
Fri, 12 Jul 2024 13:59:36 +0000 (15:59 +0200)
Follow-up for 19a44dfe4525ab01caf593a9c2beada4b412910d

If a drop-in is set from upper level, e.g. global unit_type.d/,
even if a unit is masked, its dropin_paths would still be partially
populated. However, unit_need_daemon_reload() would always
compare u->dropin_paths with empty strv in case of masked units,
resulting in it always returning true. Instead, let's ignore
dropins entirely here.

Fixes #33672

src/core/unit.c
test/units/TEST-07-PID1.issue-33672.sh

index 3f24cf27f401b57b8256aa7553149665a69d6d18..8ac0aad2d75aeddc1a6fd576f6aa34c941921099 100644 (file)
@@ -3796,8 +3796,6 @@ static bool fragment_mtime_newer(const char *path, usec_t mtime, bool path_maske
 }
 
 bool unit_need_daemon_reload(Unit *u) {
-        _cleanup_strv_free_ char **dropins = NULL;
-
         assert(u);
         assert(u->manager);
 
@@ -3813,16 +3811,20 @@ bool unit_need_daemon_reload(Unit *u) {
         if (fragment_mtime_newer(u->source_path, u->source_mtime, false))
                 return true;
 
-        if (u->load_state == UNIT_LOADED)
+        if (u->load_state == UNIT_LOADED) {
+                _cleanup_strv_free_ char **dropins = NULL;
+
                 (void) unit_find_dropin_paths(u, &dropins);
-        if (!strv_equal(u->dropin_paths, dropins))
-                return true;
 
-        /* … any drop-ins that are masked are simply omitted from the list. */
-        STRV_FOREACH(path, u->dropin_paths)
-                if (fragment_mtime_newer(*path, u->dropin_mtime, false))
+                if (!strv_equal(u->dropin_paths, dropins))
                         return true;
 
+                /* … any drop-ins that are masked are simply omitted from the list. */
+                STRV_FOREACH(path, u->dropin_paths)
+                        if (fragment_mtime_newer(*path, u->dropin_mtime, false))
+                                return true;
+        }
+
         return false;
 }
 
index ab388e32b102e5999008415f2563735c70da8177..370497c346df280f3061d4539c274a9da73d6e43 100755 (executable)
@@ -37,5 +37,4 @@ systemctl unmask "$UNIT"
 assert_eq "$(systemctl show -P NeedDaemonReload "$UNIT")" no
 
 systemctl mask "$UNIT"
-# FIXME: should be "no"
-assert_eq "$(systemctl show -P NeedDaemonReload "$UNIT")" yes
+assert_eq "$(systemctl show -P NeedDaemonReload "$UNIT")" no