Skip to content

Commit 57a5e83

Browse files
committed
install: allow removing symlinks even for units that are gone
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 5163c9b) (cherry picked from commit c26e56d) (cherry picked from commit 44c08e6) (cherry picked from commit 8c9fcb5) (cherry picked from commit e969f8b)
1 parent 25364ef commit 57a5e83

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/shared/install.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,9 @@ static int install_context_mark_for_removal(
22152215
else {
22162216
log_debug_errno(r, "Unit %s not found, removing name.", i->name);
22172217
r = install_changes_add(changes, n_changes, r, i->path ?: i->name, NULL);
2218-
if (r < 0)
2218+
/* In case there's no unit, we still want to remove any leftover symlink, even if
2219+
* the unit might have been removed already, hence treating ENOENT as non-fatal. */
2220+
if (r != -ENOENT)
22192221
return r;
22202222
}
22212223
} else if (r < 0) {

test/units/testsuite-26.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ systemctl cat "$UNIT_NAME"
264264
systemctl help "$UNIT_NAME"
265265
systemctl service-watchdogs
266266
systemctl service-watchdogs "$(systemctl service-watchdogs)"
267+
# Ensure that the enablement symlinks can still be removed after the user is gone, to avoid having leftovers
268+
systemctl enable "$UNIT_NAME"
269+
systemctl stop "$UNIT_NAME"
270+
rm -f "/usr/lib/systemd/system/$UNIT_NAME"
271+
systemctl daemon-reload
272+
systemctl disable "$UNIT_NAME"
267273

268274
# show/set-environment
269275
# Make sure PATH is set

0 commit comments

Comments
 (0)