diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/login/elogind-dbus.c | 8 | ||||
-rw-r--r-- | src/login/elogind.c | 18 | ||||
-rw-r--r-- | src/login/logind-action.c | 2 | ||||
-rw-r--r-- | src/login/logind-dbus.c | 6 | ||||
-rw-r--r-- | src/login/logind-gperf.gperf | 1 | ||||
-rw-r--r-- | src/login/logind.c | 2 | ||||
-rw-r--r-- | src/login/logind.conf.in | 9 | ||||
-rw-r--r-- | src/login/logind.h | 2 | ||||
-rw-r--r-- | src/shared/bus-util.c | 6 | ||||
-rw-r--r-- | src/shared/sleep-config.c | 12 | ||||
-rw-r--r-- | src/shared/sleep-config.h | 4 | ||||
-rw-r--r-- | src/sleep/sleep.c | 53 | ||||
-rw-r--r-- | src/sleep/sleep.h | 4 |
13 files changed, 95 insertions, 32 deletions
diff --git a/src/login/elogind-dbus.c b/src/login/elogind-dbus.c index 39f5e8cf9..bed528145 100644 --- a/src/login/elogind-dbus.c +++ b/src/login/elogind-dbus.c @@ -107,11 +107,13 @@ static int shutdown_or_sleep(Manager *m, HandleAction action) { case HANDLE_KEXEC: return run_helper(KEXEC); case HANDLE_SUSPEND: - return do_sleep("suspend", m->suspend_mode, m->suspend_state, 0); + return do_sleep(m, "suspend"); case HANDLE_HIBERNATE: - return do_sleep("hibernate", m->hibernate_mode, m->hibernate_state, 0); + return do_sleep(m, "hibernate"); case HANDLE_HYBRID_SLEEP: - return do_sleep("hybrid-sleep", m->hybrid_sleep_mode, m->hybrid_sleep_state, 0); + return do_sleep(m, "hybrid-sleep"); + case HANDLE_SUSPEND_THEN_HIBERNATE: + return do_sleep(m, "suspend-then-hibernate"); default: return -EINVAL; } diff --git a/src/login/elogind.c b/src/login/elogind.c index 90ae3d7f1..c884789f7 100644 --- a/src/login/elogind.c +++ b/src/login/elogind.c @@ -379,12 +379,13 @@ int elogind_manager_new(Manager* m) { m->test_run_flags = 0; /* Init sleep modes and states */ - m->suspend_mode = NULL; - m->suspend_state = NULL; - m->hibernate_mode = NULL; - m->hibernate_state = NULL; - m->hybrid_sleep_mode = NULL; - m->hybrid_sleep_state = NULL; + m->suspend_mode = NULL; + m->suspend_state = NULL; + m->hibernate_mode = NULL; + m->hibernate_state = NULL; + m->hybrid_sleep_mode = NULL; + m->hybrid_sleep_state = NULL; + m->hibernate_delay_sec = 0; /* If elogind should be its own controller, mount its cgroup */ if (streq(SYSTEMD_CGROUP_CONTROLLER, "_elogind")) { @@ -419,6 +420,8 @@ void elogind_manager_reset_config(Manager* m) { m->hybrid_sleep_mode = strv_new("suspend", "platform", "shutdown", NULL); if (!m->hybrid_sleep_state) m->hybrid_sleep_state = strv_new("disk", NULL); + if (!m->hibernate_delay_sec) + m->hibernate_delay_sec = 180 * USEC_PER_MINUTE; #if ENABLE_DEBUG_ELOGIND dbg_cnt = -1; @@ -445,6 +448,9 @@ void elogind_manager_reset_config(Manager* m) { while (m->hybrid_sleep_state[++dbg_cnt]) log_debug_elogind("hybrid_sleep_state[%d] = %s", dbg_cnt, m->hybrid_sleep_state[dbg_cnt]); + log_debug_elogind("hibernate_delay_sec: %ul seconds (%ul minutes)", + m->hibernate_delay_sec / USEC_PER_SEC, + m->hibernate_delay_sec / USEC_PER_MINUTE); #endif // ENABLE_DEBUG_ELOGIND } diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 0426acbfc..497164e41 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -118,6 +118,8 @@ int manager_handle_action( supported = can_sleep(m, "hibernate") > 0; else if (handle == HANDLE_HYBRID_SLEEP) supported = can_sleep(m, "hybrid-sleep") > 0; + else if (handle == HANDLE_SUSPEND_THEN_HIBERNATE) + supported = can_sleep(m, "suspend-then-hibernate") > 0; #endif // 0 else if (handle == HANDLE_KEXEC) supported = access(KEXEC, X_OK) >= 0; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 31acd57dc..2f7782a13 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1979,6 +1979,9 @@ static int method_hybrid_sleep(sd_bus_message *message, void *userdata, sd_bus_e m, message, #if 0 /// elogind uses HandleAction instead of const char* unti names SPECIAL_HYBRID_SLEEP_TARGET, +#else + HANDLE_HYBRID_SLEEP, +#endif // 0 INHIBIT_SLEEP, "org.freedesktop.login1.hibernate", "org.freedesktop.login1.hibernate-multiple-sessions", @@ -1992,9 +1995,10 @@ static int method_suspend_then_hibernate(sd_bus_message *message, void *userdata return method_do_shutdown_or_sleep( m, message, +#if 0 /// elogind uses HandleAction instead of const char* unti names SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET, #else - HANDLE_HYBRID_SLEEP, + HANDLE_SUSPEND_THEN_HIBERNATE, #endif // 0 INHIBIT_SLEEP, "org.freedesktop.login1.hibernate", diff --git a/src/login/logind-gperf.gperf b/src/login/logind-gperf.gperf index 80e9e8c20..c8523fbdf 100644 --- a/src/login/logind-gperf.gperf +++ b/src/login/logind-gperf.gperf @@ -24,6 +24,7 @@ Sleep.HibernateMode, config_parse_strv, 0, offsetof(Manag Sleep.HibernateState, config_parse_strv, 0, offsetof(Manager, hibernate_state) Sleep.HybridSleepMode, config_parse_strv, 0, offsetof(Manager, hybrid_sleep_mode) Sleep.HybridSleepState, config_parse_strv, 0, offsetof(Manager, hybrid_sleep_state) +Sleep.HibernateDelaySec, config_parse_sec, 0, offsetof(Manager, hibernate_delay_sec), #endif // 1 #if 0 /// UNNEEDED by elogind # Login.NAutoVTs, config_parse_n_autovts, 0, offsetof(Manager, n_autovts) diff --git a/src/login/logind.c b/src/login/logind.c index b60536700..4c4577965 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1314,8 +1314,6 @@ int main(int argc, char *argv[]) { if ( r < 0 && (-EEXIST != r) ) return log_error_errno(r, "Failed to create /run/systemd/machines : %m"); #endif // 0 - goto finish; - } (void) manager_parse_config_file(m); diff --git a/src/login/logind.conf.in b/src/login/logind.conf.in index 1794014cc..6da3f164d 100644 --- a/src/login/logind.conf.in +++ b/src/login/logind.conf.in @@ -35,3 +35,12 @@ #RemoveIPC=yes #InhibitorsMax=8192 #SessionsMax=8192 + +[Sleep] +#SuspendState=mem standby freeze +#SuspendMode= +#HibernateState=disk +#HibernateMode=platform shutdown +#HybridSleepState=disk +#HybridSleepMode=suspend platform shutdown +#HibernateDelaySec=10800 diff --git a/src/login/logind.h b/src/login/logind.h index 48fc61965..3f17d5d6d 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -116,7 +116,7 @@ struct Manager { char **suspend_state, **suspend_mode; char **hibernate_state, **hibernate_mode; char **hybrid_sleep_state, **hybrid_sleep_mode; - + usec_t hibernate_delay_sec; #endif // 0 sd_event_source *inhibit_timeout_source; diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index b33a7272d..c3be78769 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1302,16 +1302,18 @@ int bus_connect_transport(BusTransport transport, const char *host, bool user, s #if 0 /// elogind does not support a user bus if (user) r = sd_bus_default_user(&bus); -#endif // 0 else { if (sd_booted() <= 0) { /* Print a friendly message when the local system is actually not running systemd as PID 1. */ - log_error("System has not been booted with elogind as init system (PID 1). Can't operate."); + log_error("System has not been booted with systemd as init system (PID 1). Can't operate."); return -EHOSTDOWN; } +#endif // 0 r = sd_bus_default_system(&bus); +#if 0 /// No closing bracket with elogind... Ain't we simple? ;-) } +#endif // 0 break; case BUS_TRANSPORT_REMOTE: diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 3cb917358..1d7d46ac1 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -378,11 +378,19 @@ static bool can_s2h(Manager *m) { #if 0 /// elogind has to ask the manager for some stuff int can_sleep(const char *verb) { + _cleanup_strv_free_ char **modes = NULL, **states = NULL; + int r; #else int can_sleep(Manager *m, const char *verb) { + assert(m); + + char **modes = streq(verb, "suspend") ? m->suspend_mode : + streq(verb, "hibernate") ? m->hibernate_mode : + m->hybrid_sleep_mode; + char **states = streq(verb, "suspend") ? m->suspend_state : + streq(verb, "hibernate") ? m->hibernate_state : + m->hybrid_sleep_state; #endif // 0 - _cleanup_strv_free_ char **modes = NULL, **states = NULL; - int r; assert(STR_IN_SET(verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate")); diff --git a/src/shared/sleep-config.h b/src/shared/sleep-config.h index 026849cb8..b29165143 100644 --- a/src/shared/sleep-config.h +++ b/src/shared/sleep-config.h @@ -10,11 +10,11 @@ int parse_sleep_config(const char *verb, char ***modes, char ***states, usec_t * #endif // 0 int find_hibernate_location(char **device, char **type, size_t *size, size_t *used); -#if 0 /// UNNEEDED by elogind +#if 0 /// elogind has to transport its manager instance int can_sleep(const char *verb); int can_sleep_disk(char **types); int can_sleep_state(char **types); #else #include <logind.h> -int can_sleep(Manager* m, const char *verb); +int can_sleep(Manager *m, const char *verb); #endif // 0 diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index cf5f49bec..fba7b9baf 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -6,7 +6,7 @@ //#include <errno.h> //#include <getopt.h> -//#include <linux/fiemap.h> +#include <linux/fiemap.h> //#include <stdio.h> #include "sd-messages.h" @@ -133,7 +133,22 @@ static int write_state(FILE **f, char **states) { return r; } +#if 0 /// elogind uses the values stored in its manager instance static int execute(char **modes, char **states) { +#else +static int execute(Manager *m, const char *verb) { + assert(m); + + if (verb) + arg_verb = (char*)verb; + + char **modes = streq(arg_verb, "suspend") ? m->suspend_mode : + streq(arg_verb, "hibernate") ? m->hibernate_mode : + m->hybrid_sleep_mode; + char **states = streq(arg_verb, "suspend") ? m->suspend_state : + streq(arg_verb, "hibernate") ? m->hibernate_state : + m->hybrid_sleep_state; +#endif // 0 char *arguments[] = { NULL, @@ -211,10 +226,17 @@ static int write_wakealarm(const char *str) { return 0; } +#if 0 /// elogind uses the values stored in its manager instance static int execute_s2h(usec_t hibernate_delay_sec) { _cleanup_strv_free_ char **hibernate_modes = NULL, **hibernate_states = NULL, **suspend_modes = NULL, **suspend_states = NULL; +#else +static int execute_s2h(Manager *m) { + assert(m); + + usec_t hibernate_delay_sec = m->hibernate_delay_sec; +#endif // 0 usec_t orig_time, cmp_time; char time_str[DECIMAL_STR_MAX(uint64_t)]; int r; @@ -244,7 +266,11 @@ static int execute_s2h(usec_t hibernate_delay_sec) { log_debug("Set RTC wake alarm for %s", time_str); +#if 0 /// elogind uses its manager instance values r = execute(suspend_modes, suspend_states); +#else + r = execute(m, "suspend"); +#endif // 0 if (r < 0) return r; @@ -261,7 +287,11 @@ static int execute_s2h(usec_t hibernate_delay_sec) { /* if woken up after alarm time, hibernate */ if (cmp_time >= orig_time) +#if 0 /// elogind uses its manager instance values r = execute(hibernate_modes, hibernate_states); +#else + r = execute(m, "hibernate"); +#endif // 0 return r; } @@ -349,21 +379,22 @@ int main(int argc, char *argv[]) { if (r < 0) goto finish; -#else -int do_sleep(const char *verb, char **modes, char **states, usec_t delay) { - int r; - - assert(verb); - arg_verb = (char*)verb; -#endif // 0 if (streq(arg_verb, "suspend-then-hibernate")) r = execute_s2h(delay); else r = execute(modes, states); -#if 0 /// In elogind we give the result back, no interpretation here. -finish: return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} #else - return r; +int do_sleep(Manager *m, const char *verb) { + assert(verb); + assert(m); + + arg_verb = (char*)verb; + + if (streq(arg_verb, "suspend-then-hibernate")) + return execute_s2h(m); + + return execute(m, NULL); } #endif // 0 diff --git a/src/sleep/sleep.h b/src/sleep/sleep.h index 2c35d20e6..eeffa21e2 100644 --- a/src/sleep/sleep.h +++ b/src/sleep/sleep.h @@ -21,8 +21,8 @@ along with elogind; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "time-util.h" +#include <logind.h> -int do_sleep(const char *verb, char **modes, char **states, usec_t delay); +int do_sleep(Manager *m, const char *verb); #endif // ELOGIND_SRC_SLEEP_SLEEP_H_INCLUDED |