From c53fc8aca3ecb52f87613176ccf23da224f8970a Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 8 Jul 2012 19:47:31 +1000 Subject: [PATCH] wakealarmd: cope with delta between system time and RTC time. If system time is different from RTC time, we need to allow for that difference when setting an alarm for a wakeup call. Signed-off-by: NeilBrown --- wakealarmd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wakealarmd.c b/wakealarmd.c index dfd6adb..51d79cd 100644 --- a/wakealarmd.c +++ b/wakealarmd.c @@ -182,12 +182,24 @@ static int do_suspend(void *data) return 1; if (state->conns->stamp > now + 4) { - int fd = open("/sys/class/rtc/rtc0/wakealarm", O_WRONLY); + int fd = open("/sys/class/rtc/rtc0/since_epoch", O_RDONLY); + time_t rtc_now = now; + if (fd) { + char buf[20]; + int n = read(fd, buf, 20); + close(fd); + if (n > 1 && n < 20) { + buf[n] = 0; + rtc_now = strtoul(buf, NULL, 10); + } + } + fd = open("/sys/class/rtc/rtc0/wakealarm", O_WRONLY); if (fd >= 0) { char buf[20]; write(fd, "0\n", 2); sprintf(buf, "%lld\n", - (long long)state->conns->stamp - 2); + (long long)state->conns->stamp + - now + rtc_now - 2); write(fd, buf, strlen(buf)); close(fd); } -- 2.43.0