From 2148b05182c755d74fd17b087f3ff37904df0b8c Mon Sep 17 00:00:00 2001 From: David Brownell Date: Fri, 30 Nov 2007 13:42:41 -0800 Subject: [PATCH] rtcwake: misc cleanups Cleanups for rtcwake: - Minor doc updates: highlight the framebuffer problem, give correct history of this code - Improve debug output - Fix some linelength bugs Note that this code predated the sysfs "wakealarm" mechanism, and works around several now-fixed bugs in the kernel RTC framework. Nowadays it would make sense to make this program use only the sysfs interface to the RTC, using "since_epoch" instead of RTC_RD_TIME and "wakealarm" instead of the four other ioctls. That could simplify the mess involved in timezone handling. Signed-off-by: David Brownell Signed-off-by: Karel Zak --- sys-utils/rtcwake.8 | 11 ++++++++--- sys-utils/rtcwake.c | 48 ++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/sys-utils/rtcwake.8 b/sys-utils/rtcwake.8 index dde28441..c06fb211 100644 --- a/sys-utils/rtcwake.8 +++ b/sys-utils/rtcwake.8 @@ -76,15 +76,20 @@ is the time in seconds since 1970-01-01, 00:00 UTC. Use the Use standby state \fImode\fP. Valid values are \fIstandby\fP, \fImem\fP, \fIdisk\fP and \fIon\fP (no suspend). The default is \fIstandby\fP. +.SH NOTES +Some PC systems can't currently exit sleep states such as \fImem\fP +using only the kernel code accessed by this driver. +They need help from userspace code to make the framebuffer work again. .SH HISTORY -The program first appeared as kernel commit message for Linux 2.6 in the GIT +The program was posted several times on LKML and other lists +before appearing in kernel commit message for Linux 2.6 in the GIT commit 87ac84f42a7a580d0dd72ae31d6a5eb4bfe04c6d. .SH AVAILABILITY The rtcwake command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. .SH AUTHOR -The program was written by David Brownell and improved by -Bernhard Walle . +The program was written by David Brownell +and improved by Bernhard Walle . .SH COPYRIGHT This is free software. You may redistribute copies of it under the terms of the GNU General Public License . diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 092895fe..5fbd6da7 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -16,6 +16,7 @@ * The best way to set the system's RTC is so that it holds the current * time in UTC. Use the "-l" flag to tell this program that the system * RTC uses a local timezone instead (maybe you dual-boot MS-Windows). + * That flag should not be needed on systems with adjtime support. */ #include @@ -163,14 +164,18 @@ static int get_basetimes(int fd) } if (verbose) { - if (clock_mode == CM_LOCAL) { - printf("\ttzone = %ld\n", timezone); - printf("\ttzname = %s\n", tzname[daylight]); - gmtime_r(&rtc_time, &tm); - } - printf("\tsystime = %ld, (UTC) %s\n", + /* Unless the system uses UTC, either delta or tzone + * reflects a seconds offset from UTC. The value can + * help sort out problems like bugs in your C library. + */ + printf("\tdelta = %ld\n", sys_time - rtc_time); + printf("\ttzone = %ld\n", timezone); + + printf("\ttzname = %s\n", tzname[daylight]); + gmtime_r(&rtc_time, &tm); + printf("\tsystime = %ld, (UTC) %s", (long) sys_time, asctime(gmtime(&sys_time))); - printf("\trtctime = %ld, (UTC) %s\n", + printf("\trtctime = %ld, (UTC) %s", (long) rtc_time, asctime(&tm)); } @@ -190,11 +195,14 @@ static int setup_alarm(int fd, time_t *wakeup) wake.time.tm_mday = tm->tm_mday; wake.time.tm_mon = tm->tm_mon; wake.time.tm_year = tm->tm_year; - wake.time.tm_wday = tm->tm_wday; - wake.time.tm_yday = tm->tm_yday; - wake.time.tm_isdst = tm->tm_isdst; + /* wday, yday, and isdst fields are unused by Linux */ + wake.time.tm_wday = -1; + wake.time.tm_yday = -1; + wake.time.tm_isdst = -1; - /* many rtc alarms only support up to 24 hours from 'now' ... */ + /* 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")); @@ -204,8 +212,6 @@ static int setup_alarm(int fd, time_t *wakeup) perror(_("enable rtc alarm")); return 0; } - - /* ... so use the "more than 24 hours" request only if we must */ } else { /* avoid an extra AIE_ON call */ wake.enabled = 1; @@ -321,8 +327,9 @@ int main(int argc, char **argv) suspend = strdup(optarg); break; } - fprintf(stderr, _("%s: unrecognized suspend state '%s'\n"), - progname, optarg); + fprintf(stderr, + _("%s: unrecognized suspend state '%s'\n"), + progname, optarg); usage(EXIT_FAILURE); /* alarm time, seconds-to-sleep (relative) */ @@ -376,10 +383,10 @@ int main(int argc, char **argv) printf(_("%s: assuming RTC uses UTC ...\n"), progname); clock_mode = CM_UTC; } - if (verbose) - printf(clock_mode == CM_UTC ? _("Using UTC time.\n") : - _("Using local time.\n")); } + if (verbose) + printf(clock_mode == CM_UTC ? _("Using UTC time.\n") : + _("Using local time.\n")); if (!alarm && !seconds) { fprintf(stderr, _("%s: must provide wake time\n"), progname); @@ -423,8 +430,9 @@ int main(int argc, char **argv) alarm, sys_time, rtc_time, seconds); if (alarm) { if (alarm < sys_time) { - fprintf(stderr, _("%s: time doesn't go backward to %s\n"), - progname, ctime(&alarm)); + fprintf(stderr, + _("%s: time doesn't go backward to %s\n"), + progname, ctime(&alarm)); exit(EXIT_FAILURE); } alarm += sys_time - rtc_time; -- 2.39.5