summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys-utils/rtcwake.c23
1 files changed, 19 insertions, 4 deletions
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;