we need to pass back the rtc device name that was actually used so that we can turn...
authorMike Frysinger <vapier@gentoo.org>
Fri, 15 Feb 2008 07:19:03 +0000 (07:19 -0000)
committerMike Frysinger <vapier@gentoo.org>
Fri, 15 Feb 2008 07:19:03 +0000 (07:19 -0000)
include/rtc_.h
libbb/rtc.c
util-linux/hwclock.c
util-linux/rtcwake.c

index 50b60dd2943468dfebd517ac697bdee14e5bfd49..df359da7429718f054dcd47944d8b962fa077112 100644 (file)
@@ -10,7 +10,7 @@
 #include "libbb.h"
 
 extern int rtc_adjtime_is_utc(void);
-extern int rtc_xopen(const char *default_rtc, int flags);
+extern int rtc_xopen(const char **default_rtc, int flags);
 extern time_t rtc_read_time(int fd, int utc);
 
 
index 4cbf32206c79450c4d0f4fb5b7c1a1a86e516791..78f10c65d148cba0a561693f3e7962c9ab492b7a 100644 (file)
@@ -40,21 +40,23 @@ int rtc_adjtime_is_utc(void)
        return utc;
 }
 
-int rtc_xopen(const char *default_rtc, int flags)
+int rtc_xopen(const char **default_rtc, int flags)
 {
        int rtc;
 
-       if (!default_rtc) {
-               rtc = open("/dev/rtc", flags);
+       if (!*default_rtc) {
+               *default_rtc = "/dev/rtc";
+               rtc = open(*default_rtc, flags);
                if (rtc >= 0)
                        return rtc;
-               rtc = open("/dev/rtc0", flags);
+               *default_rtc = "/dev/rtc0";
+               rtc = open(*default_rtc, flags);
                if (rtc >= 0)
                        return rtc;
-               default_rtc = "/dev/misc/rtc";
+               *default_rtc = "/dev/misc/rtc";
        }
 
-       return xopen(default_rtc, flags);
+       return xopen(*default_rtc, flags);
 }
 
 time_t rtc_read_time(int fd, int utc)
index b581d26048d65dc1ced869adb8e256c0f9eb7e47..f226535fa4e89bc17317cfe0948e425cdcce5716 100644 (file)
@@ -25,7 +25,7 @@ static time_t read_rtc(int utc)
        time_t ret;
        int fd;
 
-       fd = rtc_xopen(rtcname, O_RDONLY);
+       fd = rtc_xopen(&rtcname, O_RDONLY);
        ret = rtc_read_time(fd, utc);
        close(fd);
 
@@ -35,7 +35,7 @@ static time_t read_rtc(int utc)
 static void write_rtc(time_t t, int utc)
 {
        struct tm tm;
-       int rtc = rtc_xopen(rtcname, O_WRONLY);
+       int rtc = rtc_xopen(&rtcname, O_WRONLY);
 
        tm = *(utc ? gmtime(&t) : localtime(&t));
        tm.tm_isdst = 0;
index c7d5a4c129a064df54878afa11cc30fb8c69f428..2b1ab1fcaab02457093007bde6b87c491c5c8a8c 100644 (file)
@@ -45,7 +45,7 @@ static int may_wakeup(const char *rtcname)
                return 0;
 
        /* wakeup events could be disabled or not supported */
-       return strcmp(buf, "enabled\n") == 0;
+       return strncmp(buf, "enabled\n", 8) == 0;
 }
 
 static void setup_alarm(int fd, time_t *wakeup)
@@ -159,11 +159,11 @@ int rtcwake_main(int argc, char **argv)
        /* the rtcname is relative to /dev */
        xchdir("/dev");
 
-       if (strcmp(suspend, "on") != 0 && !may_wakeup(rtcname))
-               bb_error_msg_and_die("%s not enabled for wakeup events", rtcname);
-
        /* this RTC must exist and (if we'll sleep) be wakeup-enabled */
-       fd = rtc_xopen(rtcname, O_RDONLY);
+       fd = rtc_xopen(&rtcname, O_RDONLY);
+
+       if (strcmp(suspend, "on") && !may_wakeup(rtcname))
+               bb_error_msg_and_die("%s not enabled for wakeup events", rtcname);
 
        /* relative or absolute alarm time, normalized to time_t */
        sys_time = time(0);
@@ -184,7 +184,7 @@ int rtcwake_main(int argc, char **argv)
        fflush(stdout);
        usleep(10 * 1000);
 
-       if (!strcmp(suspend, "on"))
+       if (strcmp(suspend, "on"))
                suspend_system(suspend);
        else {
                /* "fake" suspend ... we'll do the delay ourselves */