summaryrefslogtreecommitdiffstats
path: root/sys-utils/rtcwake.c
diff options
context:
space:
mode:
authorGabriel Burt2008-08-05 07:18:52 +0200
committerKarel Zak2008-08-06 12:19:46 +0200
commitfc18118430fae01d578440560a91bf7035f310d4 (patch)
tree7410b69d73c80771f97c2d3399a87b9f8a2b9a2f /sys-utils/rtcwake.c
parentscript: don't flush input when starting script (diff)
downloadkernel-qcow2-util-linux-fc18118430fae01d578440560a91bf7035f310d4.tar.gz
kernel-qcow2-util-linux-fc18118430fae01d578440560a91bf7035f310d4.tar.xz
kernel-qcow2-util-linux-fc18118430fae01d578440560a91bf7035f310d4.zip
rtcwake: prefer RTC_WKALM_SET over RTC_ALM_SET
rtcwake: Prefer RTC_WKALM_SET over RTC_ALM_SET, fixing bug with not waking up with new RTCs. Also, return error if unable to set the alarm. Signed-off-by: Gabriel Burt <gburt@novell.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/rtcwake.c')
-rw-r--r--sys-utils/rtcwake.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index d1e78f60f..57043983d 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -211,25 +211,24 @@ static int setup_alarm(int fd, time_t *wakeup)
wake.time.tm_yday = -1;
wake.time.tm_isdst = -1;
- /* many rtc alarms only support up to 24 hours from 'now',
- * so use the "more than 24 hours" request only if we must
- */
- if ((rtc_time + (24 * 60 * 60)) > *wakeup) {
- if (ioctl(fd, RTC_ALM_SET, &wake.time) < 0) {
- perror(_("set rtc alarm"));
- return 0;
- }
- if (ioctl(fd, RTC_AIE_ON, 0) < 0) {
- perror(_("enable rtc alarm"));
- return 0;
- }
- } else {
- /* avoid an extra AIE_ON call */
- wake.enabled = 1;
-
- if (ioctl(fd, RTC_WKALM_SET, &wake) < 0) {
+ wake.enabled = 1;
+ /* First try the preferred RTC_WKALM_SET */
+ if (ioctl(fd, RTC_WKALM_SET, &wake) < 0) {
+ wake.enabled = 0;
+ /* Fall back on the non-preferred way of setting wakeups; only
+ * works for alarms < 24 hours from now */
+ if ((rtc_time + (24 * 60 * 60)) > *wakeup) {
+ if (ioctl(fd, RTC_ALM_SET, &wake.time) < 0) {
+ perror(_("set rtc alarm"));
+ return -1;
+ }
+ if (ioctl(fd, RTC_AIE_ON, 0) < 0) {
+ perror(_("enable rtc alarm"));
+ return -1;
+ }
+ } else {
perror(_("set rtc wake alarm"));
- return 0;
+ return -1;
}
}