core/swap: refuse to run swapoff without a device
Issue: https://github.com/systemd/systemd/issues/43442
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user