From: Lennart Poettering Date: Wed, 24 Oct 2018 10:52:11 +0000 (+0200) Subject: sleep: let's turn off the RTC alarm time ASAP X-Git-Tag: v240~475^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eabcf200f7ab271f3f684f380464ad2f8e53fb06;p=thirdparty%2Fsystemd.git sleep: let's turn off the RTC alarm time ASAP Let's be a tiny bit more careful here. Also, let's rearrange things to simplify them a bit, and to not use "r" outside of its immediate scope of validity. --- diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index bd4c104ad07..771a8cd48bd 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -246,22 +246,22 @@ static int execute_s2h(usec_t hibernate_delay_sec) { if (r < 0) return r; - r = rtc_read_time(&cmp_time); + /* Reset RTC right-away */ + r = rtc_write_wake_alarm(0); if (r < 0) return r; - /* reset RTC */ - r = rtc_write_wake_alarm(0); + r = rtc_read_time(&cmp_time); if (r < 0) return r; log_debug("Woke up at %"PRIu64, cmp_time); - /* if woken up after alarm time, hibernate */ - if (cmp_time >= wake_time) - r = execute(hibernate_modes, hibernate_states); + if (cmp_time < wake_time) /* We woke up before the alarm time, we are done. */ + return 0; - return r; + /* If woken up after alarm time, hibernate */ + return execute(hibernate_modes, hibernate_states); } static int help(void) {