diff --git a/src/core/swap.c b/src/core/swap.c index 0d45246dd5..38a2b347e2 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -873,6 +873,17 @@ static void swap_enter_deactivating(Swap *s) { assert(s); + /* A swap unit can be active without ever having been loaded, and hence without a device: an + * orphaned unit that still has a swapon running is adopted by swap_coldplug() on purpose, and + * swap_sigchld_event() moves it to SWAP_ACTIVE once that process exits successfully. There is + * nothing to deactivate for such a unit, and calling swapoff without an argument certainly isn't + * it — go to dead, like swap_process_proc_swaps() does when a unit disappears from /proc/swaps. */ + if (isempty(s->what)) { + log_unit_warning(UNIT(s), "Swap unit has no device, assuming it is already deactivated."); + swap_enter_dead(s, SWAP_SUCCESS); + return; + } + s->control_command_id = SWAP_EXEC_DEACTIVATE; s->control_command = s->exec_command + SWAP_EXEC_DEACTIVATE;