X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fswap.c;h=cb19d0f1236e50a75e35de76aef7761434a291a6;hb=4968105790c65af58d4ab42bffa2a4bedc0be8ee;hp=346a5fd7121af758c973fd06e3b71fbbb8594f58;hpb=31938a8560a664c32a9d72f1fc2d4347b232e6e9;p=elogind.git diff --git a/src/core/swap.c b/src/core/swap.c index 346a5fd71..cb19d0f12 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -35,7 +35,7 @@ #include "unit-name.h" #include "dbus-swap.h" #include "special.h" -#include "bus-errors.h" +#include "bus-common-errors.h" #include "exit-status.h" #include "def.h" #include "path-util.h" @@ -1453,6 +1453,21 @@ static int swap_get_timeout(Unit *u, uint64_t *timeout) { return 1; } +static bool swap_supported(Manager *m) { + static int supported = -1; + + /* If swap support is not available in the kernel, or we are + * running in a container we don't support swap units, and any + * attempts to starting one should fail immediately. */ + + if (supported < 0) + supported = + access("/proc/swaps", F_OK) >= 0 && + detect_container(NULL) <= 0; + + return supported; +} + static const char* const swap_state_table[_SWAP_STATE_MAX] = { [SWAP_DEAD] = "dead", [SWAP_ACTIVATING] = "activating", @@ -1539,6 +1554,7 @@ const UnitVTable swap_vtable = { .enumerate = swap_enumerate, .shutdown = swap_shutdown, + .supported = swap_supported, .status_message_formats = { .starting_stopping = {