Merge pull request #33711 from dtardon/masked-unit-NeedDaemonReload

Fix `NeedDaemonReload=` for masked units with drop-ins
This commit is contained in:
Luca Boccassi
2024-07-13 14:22:05 +02:00
committed by GitHub
2 changed files with 51 additions and 9 deletions
+11 -9
View 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)
(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;
}
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
set -eux
set -o pipefail
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
# systemctl status always shows daemon-reload warning for a masked service with drop-ins
# Issue: https://github.com/systemd/systemd/issues/33672
UNIT=test-23-NeedDaemonReload.service
cleanup() {
rm -rf /run/systemd/system/"$UNIT" /run/systemd/system/"$UNIT".d
systemctl daemon-reload
}
trap cleanup EXIT
cat > /run/systemd/system/"$UNIT" <<EOF
[Service]
ExecStart=/usr/bin/true
EOF
mkdir /run/systemd/system/"$UNIT".d
cat > /run/systemd/system/"$UNIT".d/desc.conf <<EOF
[Unit]
Description=Test NeedDaemonReload status of a masked unit with drop-ins
EOF
systemctl daemon-reload
systemctl unmask "$UNIT"
assert_eq "$(systemctl show -P NeedDaemonReload "$UNIT")" no
systemctl mask "$UNIT"
assert_eq "$(systemctl show -P NeedDaemonReload "$UNIT")" no