From 11b3775f514f521f353741ff6ac4d66cf0e928e8 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 8 Jul 2024 17:12:20 +0200 Subject: [PATCH] core/unit: ignore dropins for masked units completely when checking need_reload 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 | 20 +++++++++++--------- test/units/TEST-07-PID1.issue-33672.sh | 3 +-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index 3f24cf27f40..8ac0aad2d75 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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) - (void) unit_find_dropin_paths(u, &dropins); - if (!strv_equal(u->dropin_paths, dropins)) - return true; + if (u->load_state == UNIT_LOADED) { + _cleanup_strv_free_ char **dropins = NULL; - /* … 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)) + (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)) + return true; + } + return false; } diff --git a/test/units/TEST-07-PID1.issue-33672.sh b/test/units/TEST-07-PID1.issue-33672.sh index ab388e32b10..370497c346d 100755 --- a/test/units/TEST-07-PID1.issue-33672.sh +++ b/test/units/TEST-07-PID1.issue-33672.sh @@ -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