From 829eab67e6f279ef76e18df7d5fe36ffe43979e1 Mon Sep 17 00:00:00 2001 From: Giacomo Date: Wed, 12 Sep 2012 17:33:39 +0000 Subject: rtcwake: doesn't reset wakealarm Disable an alarm use the same logic used to enable it: first try RTC_WKALM_SET with the "enabled" flag set to false, if it fails fall back to RTC_AIE_OFF. Signed-off-by: Giacomo Signed-off-by: Karel Zak --- sys-utils/rtcwake.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'sys-utils/rtcwake.c') diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 0e16bd388..a1fd6dc45 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -64,7 +64,6 @@ enum ClockMode { static unsigned verbose; static unsigned dryrun; -static unsigned ioctl_aie_on; /* ioctl(AIE_ON) succeeded */ enum ClockMode clock_mode = CM_AUTO; static struct option long_options[] = { @@ -243,7 +242,6 @@ static int setup_alarm(int fd, time_t *wakeup) warn(_("enable rtc alarm failed")); return -1; } - ioctl_aie_on = 1; } else { warn(_("set rtc wake alarm failed")); return -1; @@ -616,8 +614,25 @@ int main(int argc, char **argv) suspend_system(suspend); } - if (!dryrun && ioctl_aie_on && ioctl(fd, RTC_AIE_OFF, 0) < 0) - warn(_("disable rtc alarm interrupt failed")); + if (!dryrun) { + /* try to disable the alarm with the preferred RTC_WKALM_RD and + * RTC_WKALM_SET calls, if it fails fall back to RTC_AIE_OFF + */ + struct rtc_wkalrm wake; + + if (ioctl(fd, RTC_WKALM_RD, &wake) < 0) { + if (ioctl(fd, RTC_AIE_OFF, 0) < 0) { + warn(_("disable rtc alarm interrupt failed")); + rc = EXIT_FAILURE; + } + } else { + wake.enabled = 0; + if (ioctl(fd, RTC_WKALM_SET, &wake) < 0) { + warn(_("disable rtc alarm interrupt failed")); + rc = EXIT_FAILURE; + } + } + } close(fd); return rc; -- cgit v1.2.3-55-g7522