From: Giacomo Date: Wed, 12 Sep 2012 17:33:39 +0000 (+0000) Subject: rtcwake: doesn't reset wakealarm X-Git-Tag: v2.23-rc1~694 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=829eab67e6f279ef76e18df7d5fe36ffe43979e1;p=thirdparty%2Futil-linux.git 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 --- diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 0e16bd388e..a1fd6dc458 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;