Skip to content

Commit

Permalink
install: allow removing symlinks even for units that are gone
Browse files Browse the repository at this point in the history
If a symlink is leftover, still allow cleaning it up via 'disable'. This
happens when a unit is stopped and removed, but not disabled, and a reload
has already happened. At that point, cleaning up the old symlinks becomes
impossible through the APIs, and needs to be done manually. Always allow
cleaning up symlinks, if they exist, by only erroring out if there is an
OOM.

Follow-up for f31f10a

(cherry picked from commit 5163c9b1e56293b1bb2803420613c5b374570892)
(cherry picked from commit c26e56d08f30a2946dfa1d03781c63bfa9f56c1d)
(cherry picked from commit 44c08e6)
(cherry picked from commit 8c9fcb5)
(cherry picked from commit e969f8b)
  • Loading branch information
bluca committed Jun 25, 2024
1 parent 25364ef commit 57a5e83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/shared/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,9 @@ static int install_context_mark_for_removal(
else {
log_debug_errno(r, "Unit %s not found, removing name.", i->name);
r = install_changes_add(changes, n_changes, r, i->path ?: i->name, NULL);
if (r < 0)
/* In case there's no unit, we still want to remove any leftover symlink, even if
* the unit might have been removed already, hence treating ENOENT as non-fatal. */
if (r != -ENOENT)
return r;
}
} else if (r < 0) {
Expand Down
6 changes: 6 additions & 0 deletions test/units/testsuite-26.sh
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ systemctl cat "$UNIT_NAME"
systemctl help "$UNIT_NAME"
systemctl service-watchdogs
systemctl service-watchdogs "$(systemctl service-watchdogs)"
# Ensure that the enablement symlinks can still be removed after the user is gone, to avoid having leftovers
systemctl enable "$UNIT_NAME"
systemctl stop "$UNIT_NAME"
rm -f "/usr/lib/systemd/system/$UNIT_NAME"
systemctl daemon-reload
systemctl disable "$UNIT_NAME"

# show/set-environment
# Make sure PATH is set
Expand Down

0 comments on commit 57a5e83

Please sign in to comment.