diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-12-12 21:05:32 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-12-15 19:02:17 +0100 |
commit | 0faacd470dfbd24f4c6504da6f04213aa05f9d19 (patch) | |
tree | 9b13b654d993efc475f9209f8b1cf602850ee27b /src/core/swap.c | |
parent | 17d1f37d0dbd2d78b8866e1350c83a9755105144 (diff) |
unit: handle nicely of certain unit types are not supported on specific systems
Containers do not really support .device, .automount or .swap units;
Systems compiled without support for swap do not support .swap units;
Systems without kdbus do not support .busname units.
With this change attempts to start a unsupported unit types will result
in an immediate "unsupported" job result, which is a lot more
descriptive then before. Also, attempts to start device units in
containers will now immediately fail instead of causing jobs to be
enqueued that never go away.
Diffstat (limited to 'src/core/swap.c')
-rw-r--r-- | src/core/swap.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/swap.c b/src/core/swap.c index a6a23554c9..cb19d0f123 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -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 = { |