portable: detect drop-in-only attachments

Commit edea370222 (portable: remove drop-in configs even if the main unit file does not exist)
taught detach to handle leftover .service.d directories
after the main unit symlink was removed.

portable_get_state_internal() still had the same blind
spot: it only considered regular unit entries, so portablectl
is-attached could report detached while a portable drop-in directory was still present.

Handle those drop-in-only entries like detach does, preserve
the existing unit-file based enabled checks when the
main unit file is still present, and add TEST-29 coverage.

Signed-off-by: dongshengyuan <dongshengyuan@uniontech.com>
This commit is contained in:
dongshengyuan
2026-07-07 18:47:30 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 93aadbf968
commit a977bf4d06
2 changed files with 84 additions and 39 deletions
+9 -1
View File
@@ -144,9 +144,17 @@ portablectl detach --now --runtime --extension /tmp/app0 /tmp/rootdir app0
# Provides coverage for https://github.com/systemd/systemd/issues/23481
portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime /tmp/rootdir minimal-app0
portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
# attach and detach again to check if all drop-in configs are removed even if the main unit files are removed
# Attach and detach again to check if drop-in-only leftovers are still recognized and removed.
portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime /tmp/rootdir minimal-app0
rm /run/systemd/system.attached/minimal-app0*.service
status="$(portablectl is-attached --runtime /tmp/rootdir)"
[[ "${status}" == "running-runtime" ]]
systemctl stop minimal-app0.service minimal-app0-foo.service
status="$(portablectl is-attached --runtime /tmp/rootdir)"
[[ "${status}" == "attached-runtime" ]]
portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
[[ ! -d /run/systemd/system.attached/minimal-app0.service.d ]]
[[ ! -d /run/systemd/system.attached/minimal-app0-foo.service.d ]]
# The wrong file should be ignored, given the right one has the xattr set
trap 'rm -rf /var/cache/wrongext' EXIT