/* SPDX-License-Identifier: LGPL-2.1+ */
/***
- Copyright © 2013 Zbigniew Jędrzejewski-Szmek
Copyright © 2010-2017 Canonical
Copyright © 2018 Dell Inc.
***/
//#include <errno.h>
//#include <getopt.h>
-//#include <linux/fiemap.h>
+#include <linux/fiemap.h>
//#include <stdio.h>
#include "sd-messages.h"
-//#include "parse-util.h"
+#include "parse-util.h"
#include "def.h"
#include "exec-util.h"
#include "fd-util.h"
#include "fileio.h"
//#include "log.h"
-//#include "sleep-config.h"
-//#include "stdio-util.h"
-//#include "string-util.h"
+#include "sleep-config.h"
+#include "stdio-util.h"
+#include "string-util.h"
#include "strv.h"
//#include "util.h"
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,
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;
+#if 0 /// Already parsed by elogind config
r = parse_sleep_config("suspend", &suspend_modes, &suspend_states,
NULL);
if (r < 0)
&hibernate_states, NULL);
if (r < 0)
return r;
+#endif // 0
r = read_wakealarm(&orig_time);
if (r < 0)
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;
/* 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;
}
r = execute_s2h(delay);
else
r = execute(modes, states);
-finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
#else
-int do_sleep(const char *verb, char **modes, char **states) {
+int do_sleep(Manager *m, const char *verb) {
assert(verb);
+ assert(m);
+
arg_verb = (char*)verb;
- return execute(modes, states);
+
+ if (streq(arg_verb, "suspend-then-hibernate"))
+ return execute_s2h(m);
+
+ return execute(m, NULL);
}
#endif // 0