Skip to content

Commit

Permalink
core/unit: ignore dropins for masked units completely when checking n…
Browse files Browse the repository at this point in the history
…eed_reload

Follow-up for 19a44df

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 systemd#33672
  • Loading branch information
YHNdnzj authored and dtardon committed Jul 12, 2024
1 parent 8b6de9e commit 11b3775
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/core/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions test/units/TEST-07-PID1.issue-33672.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 11b3775

Please sign in to comment.