diff options
-rw-r--r-- | include/usage.h | 9 | ||||
-rw-r--r-- | util-linux/hwclock.c | 22 |
2 files changed, 21 insertions, 10 deletions
diff --git a/include/usage.h b/include/usage.h index a98d52e24..d8faa4f12 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1286,15 +1286,18 @@ | |||
1286 | " -d STRING URL decode STRING" | 1286 | " -d STRING URL decode STRING" |
1287 | 1287 | ||
1288 | #define hwclock_trivial_usage \ | 1288 | #define hwclock_trivial_usage \ |
1289 | "[-r|--show] [-s|--hctosys] [-w|--systohc] [-l|--localtime] [-u|--utc]" | 1289 | "[-r|--show] [-s|--hctosys] [-w|--systohc]" \ |
1290 | " [-l|--localtime] [-u|--utc]" \ | ||
1291 | " [-f FILE]" | ||
1290 | #define hwclock_full_usage \ | 1292 | #define hwclock_full_usage \ |
1291 | "Query and set the hardware clock (RTC)" \ | 1293 | "Query and set a hardware clock (RTC)" \ |
1292 | "\n\nOptions:\n" \ | 1294 | "\n\nOptions:\n" \ |
1293 | " -r Read hardware clock and print result\n" \ | 1295 | " -r Read hardware clock and print result\n" \ |
1294 | " -s Set the system time from the hardware clock\n" \ | 1296 | " -s Set the system time from the hardware clock\n" \ |
1295 | " -w Set the hardware clock to the current system time\n" \ | 1297 | " -w Set the hardware clock to the current system time\n" \ |
1296 | " -u The hardware clock is kept in coordinated universal time\n" \ | 1298 | " -u The hardware clock is kept in coordinated universal time\n" \ |
1297 | " -l The hardware clock is kept in local time" | 1299 | " -l The hardware clock is kept in local time\n" \ |
1300 | " -f FILE Use the specified clock (e.g. /dev/rtc2)" | ||
1298 | 1301 | ||
1299 | #define id_trivial_usage \ | 1302 | #define id_trivial_usage \ |
1300 | "[OPTIONS]... [USERNAME]" | 1303 | "[OPTIONS]... [USERNAME]" |
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index ca4238f9e..86235e989 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -35,16 +35,22 @@ struct linux_rtc_time { | |||
35 | # endif | 35 | # endif |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | static const char *rtcname; | ||
39 | |||
38 | static int xopen_rtc(int flags) | 40 | static int xopen_rtc(int flags) |
39 | { | 41 | { |
40 | int rtc; | 42 | int rtc; |
41 | rtc = open("/dev/rtc", flags); | 43 | |
42 | if (rtc < 0) { | 44 | if (!rtcname) { |
43 | rtc = open("/dev/misc/rtc", flags); | 45 | rtc = open("/dev/rtc", flags); |
44 | if (rtc < 0) | 46 | if (rtc >= 0) |
45 | bb_perror_msg_and_die("cannot access RTC"); | 47 | return rtc; |
48 | rtc = open("/dev/rtc0", flags); | ||
49 | if (rtc >= 0) | ||
50 | return rtc; | ||
51 | rtcname = "/dev/misc/rtc"; | ||
46 | } | 52 | } |
47 | return rtc; | 53 | return xopen(rtcname, flags); |
48 | } | 54 | } |
49 | 55 | ||
50 | static time_t read_rtc(int utc) | 56 | static time_t read_rtc(int utc) |
@@ -175,6 +181,7 @@ static int check_utc(void) | |||
175 | #define HWCLOCK_OPT_SHOW 0x04 | 181 | #define HWCLOCK_OPT_SHOW 0x04 |
176 | #define HWCLOCK_OPT_HCTOSYS 0x08 | 182 | #define HWCLOCK_OPT_HCTOSYS 0x08 |
177 | #define HWCLOCK_OPT_SYSTOHC 0x10 | 183 | #define HWCLOCK_OPT_SYSTOHC 0x10 |
184 | #define HWCLOCK_OPT_RTCFILE 0x20 | ||
178 | 185 | ||
179 | int hwclock_main(int argc, char **argv ); | 186 | int hwclock_main(int argc, char **argv ); |
180 | int hwclock_main(int argc, char **argv ) | 187 | int hwclock_main(int argc, char **argv ) |
@@ -189,12 +196,13 @@ int hwclock_main(int argc, char **argv ) | |||
189 | { "show", 0, 0, 'r' }, | 196 | { "show", 0, 0, 'r' }, |
190 | { "hctosys", 0, 0, 's' }, | 197 | { "hctosys", 0, 0, 's' }, |
191 | { "systohc", 0, 0, 'w' }, | 198 | { "systohc", 0, 0, 'w' }, |
199 | { "file", 1, 0, 'f' }, | ||
192 | { 0, 0, 0, 0 } | 200 | { 0, 0, 0, 0 } |
193 | }; | 201 | }; |
194 | applet_long_options = hwclock_long_options; | 202 | applet_long_options = hwclock_long_options; |
195 | #endif | 203 | #endif |
196 | opt_complementary = "?:r--ws:w--rs:s--wr:l--u:u--l"; | 204 | opt_complementary = "?:r--ws:w--rs:s--wr:l--u:u--l"; |
197 | opt = getopt32(argc, argv, "lursw"); | 205 | opt = getopt32(argc, argv, "lurswf:", &rtcname); |
198 | 206 | ||
199 | /* If -u or -l wasn't given check if we are using utc */ | 207 | /* If -u or -l wasn't given check if we are using utc */ |
200 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) | 208 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) |