diff options
author | Mike Frysinger <vapier@gentoo.org> | 2008-02-15 07:19:03 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2008-02-15 07:19:03 +0000 |
commit | 977bc6a1374ed468ec96e2202757be0c8b3592ed (patch) | |
tree | 00cd5d36831b37f1b941f38f87884d80f7e04409 | |
parent | ea915363e747d4e42215016ceaef4b19e01baf55 (diff) | |
download | busybox-w32-977bc6a1374ed468ec96e2202757be0c8b3592ed.tar.gz busybox-w32-977bc6a1374ed468ec96e2202757be0c8b3592ed.tar.bz2 busybox-w32-977bc6a1374ed468ec96e2202757be0c8b3592ed.zip |
we need to pass back the rtc device name that was actually used so that we can turn around and check its sysfs status
-rw-r--r-- | include/rtc_.h | 2 | ||||
-rw-r--r-- | libbb/rtc.c | 14 | ||||
-rw-r--r-- | util-linux/hwclock.c | 4 | ||||
-rw-r--r-- | util-linux/rtcwake.c | 12 |
4 files changed, 17 insertions, 15 deletions
diff --git a/include/rtc_.h b/include/rtc_.h index 50b60dd29..df359da74 100644 --- a/include/rtc_.h +++ b/include/rtc_.h | |||
@@ -10,7 +10,7 @@ | |||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | extern int rtc_adjtime_is_utc(void); | 12 | extern int rtc_adjtime_is_utc(void); |
13 | extern int rtc_xopen(const char *default_rtc, int flags); | 13 | extern int rtc_xopen(const char **default_rtc, int flags); |
14 | extern time_t rtc_read_time(int fd, int utc); | 14 | extern time_t rtc_read_time(int fd, int utc); |
15 | 15 | ||
16 | 16 | ||
diff --git a/libbb/rtc.c b/libbb/rtc.c index 4cbf32206..78f10c65d 100644 --- a/libbb/rtc.c +++ b/libbb/rtc.c | |||
@@ -40,21 +40,23 @@ int rtc_adjtime_is_utc(void) | |||
40 | return utc; | 40 | return utc; |
41 | } | 41 | } |
42 | 42 | ||
43 | int rtc_xopen(const char *default_rtc, int flags) | 43 | int rtc_xopen(const char **default_rtc, int flags) |
44 | { | 44 | { |
45 | int rtc; | 45 | int rtc; |
46 | 46 | ||
47 | if (!default_rtc) { | 47 | if (!*default_rtc) { |
48 | rtc = open("/dev/rtc", flags); | 48 | *default_rtc = "/dev/rtc"; |
49 | rtc = open(*default_rtc, flags); | ||
49 | if (rtc >= 0) | 50 | if (rtc >= 0) |
50 | return rtc; | 51 | return rtc; |
51 | rtc = open("/dev/rtc0", flags); | 52 | *default_rtc = "/dev/rtc0"; |
53 | rtc = open(*default_rtc, flags); | ||
52 | if (rtc >= 0) | 54 | if (rtc >= 0) |
53 | return rtc; | 55 | return rtc; |
54 | default_rtc = "/dev/misc/rtc"; | 56 | *default_rtc = "/dev/misc/rtc"; |
55 | } | 57 | } |
56 | 58 | ||
57 | return xopen(default_rtc, flags); | 59 | return xopen(*default_rtc, flags); |
58 | } | 60 | } |
59 | 61 | ||
60 | time_t rtc_read_time(int fd, int utc) | 62 | time_t rtc_read_time(int fd, int utc) |
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index b581d2604..f226535fa 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -25,7 +25,7 @@ static time_t read_rtc(int utc) | |||
25 | time_t ret; | 25 | time_t ret; |
26 | int fd; | 26 | int fd; |
27 | 27 | ||
28 | fd = rtc_xopen(rtcname, O_RDONLY); | 28 | fd = rtc_xopen(&rtcname, O_RDONLY); |
29 | ret = rtc_read_time(fd, utc); | 29 | ret = rtc_read_time(fd, utc); |
30 | close(fd); | 30 | close(fd); |
31 | 31 | ||
@@ -35,7 +35,7 @@ static time_t read_rtc(int utc) | |||
35 | static void write_rtc(time_t t, int utc) | 35 | static void write_rtc(time_t t, int utc) |
36 | { | 36 | { |
37 | struct tm tm; | 37 | struct tm tm; |
38 | int rtc = rtc_xopen(rtcname, O_WRONLY); | 38 | int rtc = rtc_xopen(&rtcname, O_WRONLY); |
39 | 39 | ||
40 | tm = *(utc ? gmtime(&t) : localtime(&t)); | 40 | tm = *(utc ? gmtime(&t) : localtime(&t)); |
41 | tm.tm_isdst = 0; | 41 | tm.tm_isdst = 0; |
diff --git a/util-linux/rtcwake.c b/util-linux/rtcwake.c index c7d5a4c12..2b1ab1fca 100644 --- a/util-linux/rtcwake.c +++ b/util-linux/rtcwake.c | |||
@@ -45,7 +45,7 @@ static int may_wakeup(const char *rtcname) | |||
45 | return 0; | 45 | return 0; |
46 | 46 | ||
47 | /* wakeup events could be disabled or not supported */ | 47 | /* wakeup events could be disabled or not supported */ |
48 | return strcmp(buf, "enabled\n") == 0; | 48 | return strncmp(buf, "enabled\n", 8) == 0; |
49 | } | 49 | } |
50 | 50 | ||
51 | static void setup_alarm(int fd, time_t *wakeup) | 51 | static void setup_alarm(int fd, time_t *wakeup) |
@@ -159,11 +159,11 @@ int rtcwake_main(int argc, char **argv) | |||
159 | /* the rtcname is relative to /dev */ | 159 | /* the rtcname is relative to /dev */ |
160 | xchdir("/dev"); | 160 | xchdir("/dev"); |
161 | 161 | ||
162 | if (strcmp(suspend, "on") != 0 && !may_wakeup(rtcname)) | ||
163 | bb_error_msg_and_die("%s not enabled for wakeup events", rtcname); | ||
164 | |||
165 | /* this RTC must exist and (if we'll sleep) be wakeup-enabled */ | 162 | /* this RTC must exist and (if we'll sleep) be wakeup-enabled */ |
166 | fd = rtc_xopen(rtcname, O_RDONLY); | 163 | fd = rtc_xopen(&rtcname, O_RDONLY); |
164 | |||
165 | if (strcmp(suspend, "on") && !may_wakeup(rtcname)) | ||
166 | bb_error_msg_and_die("%s not enabled for wakeup events", rtcname); | ||
167 | 167 | ||
168 | /* relative or absolute alarm time, normalized to time_t */ | 168 | /* relative or absolute alarm time, normalized to time_t */ |
169 | sys_time = time(0); | 169 | sys_time = time(0); |
@@ -184,7 +184,7 @@ int rtcwake_main(int argc, char **argv) | |||
184 | fflush(stdout); | 184 | fflush(stdout); |
185 | usleep(10 * 1000); | 185 | usleep(10 * 1000); |
186 | 186 | ||
187 | if (!strcmp(suspend, "on")) | 187 | if (strcmp(suspend, "on")) |
188 | suspend_system(suspend); | 188 | suspend_system(suspend); |
189 | else { | 189 | else { |
190 | /* "fake" suspend ... we'll do the delay ourselves */ | 190 | /* "fake" suspend ... we'll do the delay ourselves */ |