hwclock: support /dev/rtc0 etc

This commit is contained in:
Denis Vlasenko 2007-03-07 23:02:50 +00:00
parent 7fb8a00341
commit 673d4bbab6
2 changed files with 21 additions and 10 deletions

View File

@ -1286,15 +1286,18 @@
" -d STRING URL decode STRING" " -d STRING URL decode STRING"
#define hwclock_trivial_usage \ #define hwclock_trivial_usage \
"[-r|--show] [-s|--hctosys] [-w|--systohc] [-l|--localtime] [-u|--utc]" "[-r|--show] [-s|--hctosys] [-w|--systohc]" \
" [-l|--localtime] [-u|--utc]" \
" [-f FILE]"
#define hwclock_full_usage \ #define hwclock_full_usage \
"Query and set the hardware clock (RTC)" \ "Query and set a hardware clock (RTC)" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -r Read hardware clock and print result\n" \ " -r Read hardware clock and print result\n" \
" -s Set the system time from the hardware clock\n" \ " -s Set the system time from the hardware clock\n" \
" -w Set the hardware clock to the current system time\n" \ " -w Set the hardware clock to the current system time\n" \
" -u The hardware clock is kept in coordinated universal time\n" \ " -u The hardware clock is kept in coordinated universal time\n" \
" -l The hardware clock is kept in local time" " -l The hardware clock is kept in local time\n" \
" -f FILE Use the specified clock (e.g. /dev/rtc2)"
#define id_trivial_usage \ #define id_trivial_usage \
"[OPTIONS]... [USERNAME]" "[OPTIONS]... [USERNAME]"

View File

@ -35,16 +35,22 @@ struct linux_rtc_time {
# endif # endif
#endif #endif
static const char *rtcname;
static int xopen_rtc(int flags) static int xopen_rtc(int flags)
{ {
int rtc; int rtc;
if (!rtcname) {
rtc = open("/dev/rtc", flags); rtc = open("/dev/rtc", flags);
if (rtc < 0) { if (rtc >= 0)
rtc = open("/dev/misc/rtc", flags);
if (rtc < 0)
bb_perror_msg_and_die("cannot access RTC");
}
return rtc; return rtc;
rtc = open("/dev/rtc0", flags);
if (rtc >= 0)
return rtc;
rtcname = "/dev/misc/rtc";
}
return xopen(rtcname, flags);
} }
static time_t read_rtc(int utc) static time_t read_rtc(int utc)
@ -175,6 +181,7 @@ static int check_utc(void)
#define HWCLOCK_OPT_SHOW 0x04 #define HWCLOCK_OPT_SHOW 0x04
#define HWCLOCK_OPT_HCTOSYS 0x08 #define HWCLOCK_OPT_HCTOSYS 0x08
#define HWCLOCK_OPT_SYSTOHC 0x10 #define HWCLOCK_OPT_SYSTOHC 0x10
#define HWCLOCK_OPT_RTCFILE 0x20
int hwclock_main(int argc, char **argv ); int hwclock_main(int argc, char **argv );
int hwclock_main(int argc, char **argv ) int hwclock_main(int argc, char **argv )
@ -189,12 +196,13 @@ int hwclock_main(int argc, char **argv )
{ "show", 0, 0, 'r' }, { "show", 0, 0, 'r' },
{ "hctosys", 0, 0, 's' }, { "hctosys", 0, 0, 's' },
{ "systohc", 0, 0, 'w' }, { "systohc", 0, 0, 'w' },
{ "file", 1, 0, 'f' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
applet_long_options = hwclock_long_options; applet_long_options = hwclock_long_options;
#endif #endif
opt_complementary = "?:r--ws:w--rs:s--wr:l--u:u--l"; opt_complementary = "?:r--ws:w--rs:s--wr:l--u:u--l";
opt = getopt32(argc, argv, "lursw"); opt = getopt32(argc, argv, "lurswf:", &rtcname);
/* If -u or -l wasn't given check if we are using utc */ /* If -u or -l wasn't given check if we are using utc */
if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME))