Re: [patch linux-util-ng 2.13.0.1] misc rtcwake cleanups

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday 12 December 2007, Karel Zak wrote:
> On Wed, Dec 05, 2007 at 11:22:25AM -0800, David Brownell wrote:
> > 
> > And for the record ... see the appended, which I needed to get this
> > to work on an Ubuntu Feisty system (dual booting XP, so that the RTC
> > must match wall-clock time).  That was the reason I ended up looking
> > at this code again ... :)
> 
>  I have also system with "LOCAL" in /etc/adjtime.
> 
> > I'm not currently submitting this, since I've not had time to test
> > this the ARM systems with the suspect uClibc version.  I'd like to
> > understand a bit better how this bug arrived in the first place.
> 
>  If I well understand the alarm (RTC_[WK]ALM_SET) requires time in the
>  same mode like /dev/rtc.

Yes.  And if there are multile RTCs (e.g. only one of them has a battery,
but the other has the wakealarm) their timezones should agree.  Unless
there's a strong anti-confusion policy in place.  ;)


> > -	tm = gmtime(wakeup);
> > +	tm = localtime(wakeup);
> 
>  I think this change is correct. You needn't gmtime() in setup_alarm(),
>  because:
> 
>     - for "UTC" systems you have TZ=UTC (defined in get_basetimes())
>       so localtime() always returns UTC,
>     - for "LOCAL" systems you need the wakeup time in real timezone so
>       localtime() is also correct.
> 
>  Right?

Right.  I finally got around to testing that one ARM system, and this
behaved there too.  I think the source of the original bug was that
"hwclock" was being given inconsistent stories about the timezone used
by the RTC ... in one case local, in the other case UTC.

So, this patch should be merged (if it hasn't already been done).

- Dave



======== CUT HERE
Bugfix for rtcwake in util-linux-ng-2.13.0.1:

Timezone handling is broken in this version since it's always
passing UTC time into the kernel, even on systems where the
RTC uses the local timezone.

I think that bug must come from bugs in how the system used to
to originally develop this code handled the RTC timezone.  Both
RTCs should have been kept in UTC ... but only one of them was.

Signed-off-by: David Brownell <dbrownell@xxxxxxxxxxxxxxxxxxxxx>

---
 sys-utils/rtcwake.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

--- util-linux-ng-2.13.0.1.orig/sys-utils/rtcwake.c	2007-11-30 13:33:33.000000000 -0800
+++ util-linux-ng-2.13.0.1/sys-utils/rtcwake.c	2007-11-30 13:33:38.000000000 -0800
@@ -187,7 +187,17 @@ static int setup_alarm(int fd, time_t *w
 	struct tm		*tm;
 	struct rtc_wkalrm	wake;
 
-	tm = gmtime(wakeup);
+	/* The wakeup time is in POSIX time (more or less UTC).
+	 * Ideally RTCs use that same time; but PCs can't do that
+	 * if they need to boot MS-Windows.  Messy...
+	 *
+	 * When clock_mode == CM_UTC this process's timezone is UTC,
+	 * so we'll pass a UTC date to the RTC.
+	 *
+	 * Else clock_mode == CM_LOCAL so the time given to the RTC
+	 * will instead use the local time zone.
+	 */
+	tm = localtime(wakeup);
 
 	wake.time.tm_sec = tm->tm_sec;
 	wake.time.tm_min = tm->tm_min;
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux