From: Giacomo <giacomo.perale@gmail.com>
To: util-linux@vger.kernel.org
Subject: Re: rtcwake doesn't reset wakealarm
Date: Wed, 12 Sep 2012 17:33:39 +0000 (UTC) [thread overview]
Message-ID: <loom.20120912T191123-580@post.gmane.org> (raw)
In-Reply-To: loom.20120912T125253-285@post.gmane.org
Giacomo <giacomo.perale@...> writes:
>
> Karel Zak <kzak@...> writes:
>
> >
> > On Wed, Sep 12, 2012 at 12:09:16PM +0200, Karel Zak wrote:
> > >
> > > Let's add Paul to CC
> > >
> >
> > Please, test the patch below. I hope it fixes the problem.
> >
> > Karel
> >
>
> Hi,
>
> it should work but I'm afraid it won't fix Paul's original problem,
> because even if RTC_AIE_ON fails RTC_AIE_OFF will still be called and
> generate an error.
>
> According to "man rtc", "when using [RTC_WKALM_RD,RTC_WKALM_SET],
> RTC_AIE_ON and
> RTC_AIE_OFF are not used", so the right thing to do should be using
> RTC_AIE_OFF
> to clear the alarm only when RTC_ALM_SET+RTC_AIE_ON was used to set it up
> (that
> is, when ioctl_aie_on=1), and RTC_WKALM_SET with the "enabled" flag set to
> false
> otherwise.
>
> The attached patch works for me (I hope it doesn't get mangled in the
> posting,
> you can find it on pastebin too: http://pastebin.com/wugHPx3w).
>
> Giacomo
>
That was needlessly complex. The issue never was "don't call RTC_AIE_OFF if you
didn't call RTC_AIE_ON before," it was "don't call RTC_AIE_OFF if it is not
supported."
So to 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.
This patch works for me as well and it seems to me it's cleaner than my previous
one.
Giacomo
PS. if it's mangled http://pastebin.com/CUtVkfiQ
---
--- sys-utils/rtcwake.c 2012-07-23 23:21:56.466320628 +0200
+++ sys-utils/rtcwake.c 2012-09-12 19:22:07.772244322 +0200
@@ -64,7 +64,6 @@
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 @@
warn(_("enable rtc alarm failed"));
return -1;
}
- ioctl_aie_on = 1;
} else {
warn(_("set rtc wake alarm failed"));
return -1;
@@ -393,6 +391,8 @@
int fd;
time_t alarm = 0;
+ struct rtc_wkalrm wake;
+
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -616,8 +616,23 @@
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
+ */
+ 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;
next prev parent reply other threads:[~2012-09-12 17:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-11 11:11 rtcwake doesn't reset wakealarm Giacomo
2012-09-12 9:52 ` Giacomo
2012-09-12 10:09 ` Karel Zak
2012-09-12 10:31 ` Karel Zak
2012-09-12 14:33 ` Giacomo
2012-09-12 17:33 ` Giacomo [this message]
2012-09-13 11:25 ` Karel Zak
2012-09-13 16:31 ` Paul Fox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=loom.20120912T191123-580@post.gmane.org \
--to=giacomo.perale@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox