diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-09-26 11:17:36 +0200 |
---|---|---|
committer | Sven Eden <sven.eden@prydeworx.com> | 2018-10-29 10:18:29 +0100 |
commit | e5ac9d202b9a8189a34cecf2529afd72bc1ff024 (patch) | |
tree | 6688afee36d0e9c1b8c662f2d6ad2fe8f6fc1784 /src/sleep/sleep.c | |
parent | c3b4442469f5544a65a26e7194c50d922bec7292 (diff) |
shared/sleep-config: add switches to kill specific sleep modes
/etc/systemd/sleep.conf gains four new switches:
AllowSuspend=, AllowHibernation=, AllowSuspendThenHibernate=, AllowHybridSleep=.
Disabling specific modes was already possible by masking suspend.target,
hibernate.target, suspend-then-hibernate.target, or hybrid-sleep.target.
But this is not convenient for distributions, which want to set some defaults
based on what they want to support. Having those available as configuration
makes it easy to put a config file in /usr/lib/systemd/sleep.conf.d/ that
overrides the defaults and gives instructions how to undo that override.
(cherry picked from commit e8f1d00d695f491654d50e57c82623288d3bcbeb)
Diffstat (limited to 'src/sleep/sleep.c')
-rw-r--r-- | src/sleep/sleep.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index f104e5dac..890dae7ab 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -149,7 +149,6 @@ static int execute(Manager *m, const char *verb) { streq(arg_verb, "hibernate") ? m->hibernate_state : m->hybrid_sleep_state; #endif // 0 - char *arguments[] = { NULL, (char*) "pre", @@ -242,13 +241,11 @@ static int execute_s2h(Manager *m) { int r; #if 0 /// Already parsed by elogind config - r = parse_sleep_config("suspend", &suspend_modes, &suspend_states, - NULL); + r = parse_sleep_config("suspend", NULL, &suspend_modes, &suspend_states, NULL); if (r < 0) return r; - r = parse_sleep_config("hibernate", &hibernate_modes, - &hibernate_states, NULL); + r = parse_sleep_config("hibernate", NULL, &hibernate_modes, &hibernate_states, NULL); if (r < 0) return r; #endif // 0 @@ -363,6 +360,7 @@ static int parse_argv(int argc, char *argv[]) { } int main(int argc, char *argv[]) { + bool allow; _cleanup_strv_free_ char **modes = NULL, **states = NULL; usec_t delay = 0; int r; @@ -375,10 +373,15 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - r = parse_sleep_config(arg_verb, &modes, &states, &delay); + r = parse_sleep_config(arg_verb, &allow, &modes, &states, &delay); if (r < 0) goto finish; + if (!allow) { + log_error("Sleep mode \"%s\" is disabled by configuration, refusing.", arg_verb); + return EXIT_FAILURE; + } + if (streq(arg_verb, "suspend-then-hibernate")) r = execute_s2h(delay); else |