diff options
-rw-r--r-- | util-linux/hwclock.c | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index d78bfe374..e6f0043d0 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -9,6 +9,7 @@ | |||
9 | //config:config HWCLOCK | 9 | //config:config HWCLOCK |
10 | //config: bool "hwclock (5.9 kb)" | 10 | //config: bool "hwclock (5.9 kb)" |
11 | //config: default y | 11 | //config: default y |
12 | //config: select LONG_OPTS | ||
12 | //config: help | 13 | //config: help |
13 | //config: The hwclock utility is used to read and set the hardware clock | 14 | //config: The hwclock utility is used to read and set the hardware clock |
14 | //config: on a system. This is primarily used to set the current time on | 15 | //config: on a system. This is primarily used to set the current time on |
@@ -409,89 +410,89 @@ static void set_rtc_param(const char **pp_rtcname, char *rtc_param) | |||
409 | // -v, --verbose display more details | 410 | // -v, --verbose display more details |
410 | 411 | ||
411 | //usage:#define hwclock_trivial_usage | 412 | //usage:#define hwclock_trivial_usage |
412 | //usage: IF_LONG_OPTS( | 413 | //usage: "[-ul] [-f DEV] [-s|-w|--systz|--param-get PARAM|--param-set PARAM=VAL]" |
413 | //usage: "[-swul] [--systz] [--param-get PARAM] [--param-set PARAM=VAL] [-f DEV]" | ||
414 | //usage: ) | ||
415 | //usage: IF_NOT_LONG_OPTS( | ||
416 | //usage: "[-swult] [-g PARAM] [-p PARAM=VAL] [-f DEV]" | ||
417 | //usage: ) | ||
418 | //usage:#define hwclock_full_usage "\n\n" | 414 | //usage:#define hwclock_full_usage "\n\n" |
419 | //usage: "Show or set hardware clock (RTC)\n" | 415 | //usage: "Show or set hardware clock (RTC)\n" |
416 | //usage: "\n -f DEV Use this device (e.g. /dev/rtc2)" | ||
417 | //usage: "\n -u Assume RTC is kept in UTC" | ||
418 | //usage: "\n -l Assume RTC is kept in local time" | ||
419 | //usage: "\n (if neither is given, read from "ADJTIME_PATH")" | ||
420 | ///////: "\n -r Show RTC time" | 420 | ///////: "\n -r Show RTC time" |
421 | ///////-r is default, don't bother showing it in help | 421 | ///////-r is default, don't bother showing it in help |
422 | //usage: "\n -s Set system time from RTC" | 422 | //usage: "\n -s Set system time from RTC" |
423 | //usage: "\n -w Set RTC from system time" | 423 | //usage: "\n -w Set RTC from system time" |
424 | //usage: IF_LONG_OPTS( | ||
425 | //usage: "\n --systz Set in-kernel timezone, correct system time" | 424 | //usage: "\n --systz Set in-kernel timezone, correct system time" |
426 | //usage: "\n if RTC is kept in local time" | 425 | //usage: "\n if RTC is kept in local time" |
427 | //usage: "\n --param-get PARAM Get RTC parameter" | 426 | //usage: "\n --param-get PARAM Get RTC parameter" |
428 | //usage: "\n --param-set PARAM=VAL Set RTC parameter" | 427 | //usage: "\n --param-set PARAM=VAL Set RTC parameter" |
429 | //usage: ) | ||
430 | //usage: "\n -f DEV Use specified device (e.g. /dev/rtc2)" | ||
431 | //usage: "\n -u Assume RTC is kept in UTC" | ||
432 | //usage: "\n -l Assume RTC is kept in local time" | ||
433 | //usage: "\n (if neither is given, read from "ADJTIME_PATH")" | ||
434 | |||
435 | //TODO: get rid of incompatible -t alias to --systz? | ||
436 | |||
437 | #define HWCLOCK_OPT_LOCALTIME 0x01 | ||
438 | #define HWCLOCK_OPT_UTC 0x02 | ||
439 | #define HWCLOCK_OPT_SHOW 0x04 | ||
440 | #define HWCLOCK_OPT_HCTOSYS 0x08 | ||
441 | #define HWCLOCK_OPT_SYSTOHC 0x10 | ||
442 | #define HWCLOCK_OPT_SYSTZ 0x20 | ||
443 | #define HWCLOCK_OPT_RTCFILE 0x40 | ||
444 | #define HWCLOCK_OPT_PARAM_GET 0x80 | ||
445 | #define HWCLOCK_OPT_PARAM_SET 0x100 | ||
446 | 428 | ||
447 | int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 429 | int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
448 | int hwclock_main(int argc UNUSED_PARAM, char **argv) | 430 | int hwclock_main(int argc UNUSED_PARAM, char **argv) |
449 | { | 431 | { |
450 | const char *rtcname = NULL; | 432 | const char *rtcname = NULL; |
451 | char *param; | 433 | char *param; |
452 | unsigned opt; | 434 | unsigned opt, exclusive; |
453 | int utc; | 435 | int utc; |
454 | #if ENABLE_LONG_OPTS | 436 | #define OPT_LOCALTIME (1 << 0) |
437 | #define OPT_UTC (1 << 1) | ||
438 | #define OPT_RTCFILE (1 << 2) | ||
439 | #define OPT_SHOW (1 << 3) | ||
440 | #define OPT_HCTOSYS (1 << 4) | ||
441 | #define OPT_SYSTOHC (1 << 5) | ||
442 | #define OPT_PARAM_GET (1 << 6) | ||
443 | #define OPT_PARAM_SET (1 << 7) | ||
444 | //#define OPT_VERBOSE (1 << 8) UNUSED | ||
445 | #define OPT_SYSTZ (1 << 9) | ||
455 | static const char hwclock_longopts[] ALIGN1 = | 446 | static const char hwclock_longopts[] ALIGN1 = |
456 | "localtime\0" No_argument "l" | 447 | "localtime\0" No_argument "l" |
457 | "utc\0" No_argument "u" | 448 | "utc\0" No_argument "u" |
449 | "rtc\0" Required_argument "f" | ||
458 | "show\0" No_argument "r" | 450 | "show\0" No_argument "r" |
459 | "hctosys\0" No_argument "s" | 451 | "hctosys\0" No_argument "s" |
460 | "systohc\0" No_argument "w" | 452 | "systohc\0" No_argument "w" |
461 | "systz\0" No_argument "t" /* short opt is non-standard */ | 453 | "param-get\0" Required_argument "\xfd" /* no short equivalent */ |
462 | "rtc\0" Required_argument "f" | 454 | "param-set\0" Required_argument "\xfe" /* no short equivalent */ |
463 | "param-get\0" Required_argument "g" /* short opt is non-standard */ | 455 | "systz\0" No_argument "\xff" /* no short equivalent */ |
464 | "param-set\0" Required_argument "p" /* short opt is non-standard */ | ||
465 | ; | 456 | ; |
466 | #endif | ||
467 | opt = getopt32long(argv, | 457 | opt = getopt32long(argv, |
468 | "^""lurswtf:g:p:v" /* -v is accepted and ignored */ | 458 | "^""luf:rsw\xfd:\xfe:v" /* -v is accepted and ignored */ |
469 | "\0" | 459 | "\0" |
470 | "r--wstgp:w--rstgp:s--wrtgp:t--rswgp:g--rswtp:p--rswtg:l--u:u--l", | 460 | "l--u:u--l", |
471 | hwclock_longopts, | 461 | hwclock_longopts, |
472 | &rtcname, | 462 | &rtcname, |
473 | ¶m, | 463 | ¶m, |
474 | ¶m | 464 | ¶m |
475 | ); | 465 | ); |
466 | #if 0 //DEBUG | ||
467 | bb_error_msg("opt:0x%x", opt); | ||
468 | if (opt & OPT_PARAM_GET) bb_error_msg("OPT_PARAM_GET %s", param); | ||
469 | if (opt & OPT_PARAM_SET) bb_error_msg("OPT_PARAM_SET %s", param); | ||
470 | if (opt & OPT_SYSTZ ) bb_error_msg("OPT_SYSTZ"); | ||
471 | return 0; | ||
472 | #endif | ||
473 | /* All options apart from -luf are exclusive, enforce */ | ||
474 | exclusive = opt >> 3; | ||
475 | if ((exclusive - 1) & exclusive) /* more than one bit set? */ | ||
476 | bb_show_usage(); | ||
476 | 477 | ||
477 | /* If -u or -l wasn't given, check if we are using utc */ | 478 | /* If -u or -l wasn't given, check if we are using utc */ |
478 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) | 479 | if (opt & (OPT_UTC | OPT_LOCALTIME)) |
479 | utc = (opt & HWCLOCK_OPT_UTC); | 480 | utc = (opt & OPT_UTC); |
480 | else | 481 | else |
481 | utc = rtc_adjtime_is_utc(); | 482 | utc = rtc_adjtime_is_utc(); |
482 | 483 | ||
483 | if (opt & HWCLOCK_OPT_HCTOSYS) | 484 | if (opt & OPT_HCTOSYS) |
484 | to_sys_clock(&rtcname, utc); | 485 | to_sys_clock(&rtcname, utc); |
485 | else if (opt & HWCLOCK_OPT_SYSTOHC) | 486 | else if (opt & OPT_SYSTOHC) |
486 | from_sys_clock(&rtcname, utc); | 487 | from_sys_clock(&rtcname, utc); |
487 | else if (opt & HWCLOCK_OPT_SYSTZ) | 488 | else if (opt & OPT_SYSTZ) |
488 | set_kernel_timezone_and_clock(utc, NULL); | 489 | set_kernel_timezone_and_clock(utc, NULL); |
489 | else if (opt & HWCLOCK_OPT_PARAM_GET) | 490 | else if (opt & OPT_PARAM_GET) |
490 | get_rtc_param(&rtcname, param); | 491 | get_rtc_param(&rtcname, param); |
491 | else if (opt & HWCLOCK_OPT_PARAM_SET) | 492 | else if (opt & OPT_PARAM_SET) |
492 | set_rtc_param(&rtcname, param); | 493 | set_rtc_param(&rtcname, param); |
493 | else | 494 | else |
494 | /* default HWCLOCK_OPT_SHOW */ | 495 | /* default OPT_SHOW */ |
495 | show_clock(&rtcname, utc); | 496 | show_clock(&rtcname, utc); |
496 | 497 | ||
497 | return 0; | 498 | return 0; |