summaryrefslogtreecommitdiff
path: root/src/sleep
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-24 12:45:06 +0200
committerLennart Poettering <lennart@poettering.net>2018-10-24 12:46:12 +0200
commitf780e438fa9552809757b77b949b2a3204b65d9a (patch)
tree2f010a281465206a278225bc2b03dffd5ed2f9b7 /src/sleep
parentc16669a3094fc37e8d4fc815fcb6180a094d8ceb (diff)
downloadsystemd-f780e438fa9552809757b77b949b2a3204b65d9a.tar.gz
systemd-f780e438fa9552809757b77b949b2a3204b65d9a.tar.bz2
systemd-f780e438fa9552809757b77b949b2a3204b65d9a.zip
sleep: rework write_wakealarm() to take a numeric parameter
Also, let's rename it to rtc_write_wake_alarm(). Both changes together make sure rtc_write_wake_alarm() and rtc_read_time() are more alike in their naming and semantics.
Diffstat (limited to 'src/sleep')
-rw-r--r--src/sleep/sleep.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index f9b822bd93..f3098a6947 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -199,12 +199,15 @@ static int rtc_read_time(uint64_t *ret_sec) {
return safe_atou64(t, ret_sec);
}
-static int write_wakealarm(const char *str) {
+static int rtc_write_wake_alarm(uint64_t sec) {
+ char buf[DECIMAL_STR_MAX(uint64_t)];
int r;
- r = write_string_file("/sys/class/rtc/rtc0/wakealarm", str, 0);
+ xsprintf(buf, "%" PRIu64, sec);
+
+ r = write_string_file("/sys/class/rtc/rtc0/wakealarm", buf, 0);
if (r < 0)
- return log_error_errno(r, "Failed to write '%s' to /sys/class/rtc/rtc0/wakealarm: %m", str);
+ return log_error_errno(r, "Failed to write '%s' to /sys/class/rtc/rtc0/wakealarm: %m", buf);
return 0;
}
@@ -213,8 +216,7 @@ 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;
- usec_t orig_time, cmp_time;
- char time_str[DECIMAL_STR_MAX(uint64_t)];
+ usec_t original_time, wake_time, cmp_time;
int r;
r = parse_sleep_config("suspend", NULL, &suspend_modes, &suspend_states, NULL);
@@ -225,18 +227,16 @@ static int execute_s2h(usec_t hibernate_delay_sec) {
if (r < 0)
return r;
- r = rtc_read_time(&orig_time);
+ r = rtc_read_time(&original_time);
if (r < 0)
return log_error_errno(r, "Failed to read time: %d", r);
- orig_time += hibernate_delay_sec / USEC_PER_SEC;
- xsprintf(time_str, "%" PRIu64, orig_time);
-
- r = write_wakealarm(time_str);
+ wake_time = original_time + (hibernate_delay_sec / USEC_PER_SEC);
+ r = rtc_write_wake_alarm(wake_time);
if (r < 0)
return r;
- log_debug("Set RTC wake alarm for %s", time_str);
+ log_debug("Set RTC wake alarm for %" PRIu64, wake_time);
r = execute(suspend_modes, suspend_states);
if (r < 0)
@@ -247,14 +247,14 @@ static int execute_s2h(usec_t hibernate_delay_sec) {
return log_error_errno(r, "Failed to read time: %d", r);
/* reset RTC */
- r = write_wakealarm("0");
+ r = rtc_write_wake_alarm(0);
if (r < 0)
return r;
log_debug("Woke up at %"PRIu64, cmp_time);
/* if woken up after alarm time, hibernate */
- if (cmp_time >= orig_time)
+ if (cmp_time >= wake_time)
r = execute(hibernate_modes, hibernate_states);
return r;