diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-16 20:55:30 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-16 20:55:30 +0100 |
commit | d3c36882dc5bc5fcede9a45a6bc7a39570fba7d0 (patch) | |
tree | 4c9bb1c2b84baf964ecec6dbcd2b50067d98e19f | |
parent | 9e262f13c2e53490d69d3112ffd718c27de04d1f (diff) | |
download | busybox-w32-d3c36882dc5bc5fcede9a45a6bc7a39570fba7d0.tar.gz busybox-w32-d3c36882dc5bc5fcede9a45a6bc7a39570fba7d0.tar.bz2 busybox-w32-d3c36882dc5bc5fcede9a45a6bc7a39570fba7d0.zip |
hwclock: improve --help (-l is a compatible shortcut for --localtime)
function old new delta
packed_usage 33605 33568 -37
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/hwclock.c | 69 |
1 files changed, 50 insertions, 19 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 44cb4794e..77aa2d7c3 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -153,14 +153,12 @@ static void set_kernel_tz(const struct timezone *tz) | |||
153 | * then system time is wrong - it is offset by timezone. | 153 | * then system time is wrong - it is offset by timezone. |
154 | * --systz option corrects system time if RTC is in local time, | 154 | * --systz option corrects system time if RTC is in local time, |
155 | * and (always) sets in-kernel timezone. | 155 | * and (always) sets in-kernel timezone. |
156 | * | 156 | * (Unlike --hctosys, it does not read the RTC). |
157 | * This is an alternate option to --hctosys that does not read the | ||
158 | * hardware clock. | ||
159 | * | 157 | * |
160 | * util-linux's code has this comment: | 158 | * util-linux's code has this comment: |
161 | * RTC | settimeofday calls | 159 | * RTC | settimeofday calls |
162 | * ------|------------------------------------------------- | 160 | * ------|------------------------------------------------- |
163 | * Local | 1) warps system time*, sets PCIL* and kernel tz | 161 | * Local | 1st) warps system time*, sets PCIL* and kernel tz |
164 | * UTC | 1st) locks warp_clock 2nd) sets kernel tz | 162 | * UTC | 1st) locks warp_clock 2nd) sets kernel tz |
165 | * * only on first call after boot | 163 | * * only on first call after boot |
166 | * (PCIL is "persistent_clock_is_local" kernel internal flag, | 164 | * (PCIL is "persistent_clock_is_local" kernel internal flag, |
@@ -177,6 +175,9 @@ static void set_kernel_timezone_and_clock(int utc, const struct timeval *hctosys | |||
177 | set_kernel_tz(&tz); | 175 | set_kernel_tz(&tz); |
178 | 176 | ||
179 | /* Set kernel's timezone offset based on userspace one */ | 177 | /* Set kernel's timezone offset based on userspace one */ |
178 | //It's tempting to call tzset() and use libc global "timezone" variable | ||
179 | //...but it does NOT include DST shift (IOW: it's WRONG, usually by one hour, | ||
180 | //if DST is in effect!) Thus this ridiculous dance: | ||
180 | cur = time(NULL); | 181 | cur = time(NULL); |
181 | broken = localtime(&cur); | 182 | broken = localtime(&cur); |
182 | tz.tz_minuteswest = -broken->tm_gmtoff / 60; | 183 | tz.tz_minuteswest = -broken->tm_gmtoff / 60; |
@@ -321,30 +322,58 @@ static void from_sys_clock(const char **pp_rtcname, int utc) | |||
321 | close(rtc); | 322 | close(rtc); |
322 | } | 323 | } |
323 | 324 | ||
325 | // hwclock from util-linux 2.36.1 | ||
326 | // hwclock [function] [option...] | ||
327 | //Functions: | ||
328 | // -r, --show display the RTC time | ||
329 | // --get display drift corrected RTC time | ||
330 | // --set set the RTC according to --date | ||
331 | // -s, --hctosys set the system time from the RTC | ||
332 | // -w, --systohc set the RTC from the system time | ||
333 | // --systz send timescale configurations to the kernel | ||
334 | // -a, --adjust adjust the RTC to account for systematic drift | ||
335 | // --predict predict the drifted RTC time according to --date | ||
336 | //Options: | ||
337 | // -u, --utc the RTC timescale is UTC | ||
338 | // -l, --localtime the RTC timescale is Local | ||
339 | // -f, --rtc <file> use an alternate file to /dev/rtc0 | ||
340 | // --directisa use the ISA bus instead of /dev/rtc0 access | ||
341 | // --date <time> date/time input for --set and --predict | ||
342 | // --delay <sec> delay used when set new RTC time | ||
343 | // --update-drift update the RTC drift factor | ||
344 | // --noadjfile do not use /etc/adjtime | ||
345 | // --adjfile <file> use an alternate file to /etc/adjtime | ||
346 | // --test dry run; implies --verbose | ||
347 | // -v, --verbose display more details | ||
348 | |||
349 | //usage:#if ENABLE_FEATURE_HWCLOCK_ADJTIME_FHS | ||
350 | //usage:# define ADJTIME_PATH "/var/lib/hwclock/adjtime" | ||
351 | //usage:#else | ||
352 | //usage:# define ADJTIME_PATH "/etc/adjtime" | ||
353 | //usage:#endif | ||
324 | //usage:#define hwclock_trivial_usage | 354 | //usage:#define hwclock_trivial_usage |
325 | //usage: IF_LONG_OPTS( | 355 | //usage: IF_LONG_OPTS( |
326 | //usage: "[-swu] [--systz] [--localtime] [-f FILE]" | 356 | //usage: "[-swul] [--systz] [-f DEV]" |
327 | //usage: ) | 357 | //usage: ) |
328 | //usage: IF_NOT_LONG_OPTS( | 358 | //usage: IF_NOT_LONG_OPTS( |
329 | //usage: "[-swtlu] [-f FILE]" | 359 | //usage: "[-swult] [-f DEV]" |
330 | //usage: ) | 360 | //usage: ) |
331 | //usage:#define hwclock_full_usage "\n\n" | 361 | //usage:#define hwclock_full_usage "\n\n" |
332 | //usage: "Show or set hardware clock (RTC)\n" | 362 | //usage: "Show or set hardware clock (RTC)\n" |
333 | ///////: "\n -r Show hardware clock time" | 363 | ///////: "\n -r Show RTC time" |
334 | ///////-r is default, don't bother showing it in help | 364 | ///////-r is default, don't bother showing it in help |
335 | //usage: "\n -s Set system time from hardware clock" | 365 | //usage: "\n -s Set system time from RTC" |
336 | //usage: "\n -w Set hardware clock from system time" | 366 | //usage: "\n -w Set RTC from system time" |
337 | //usage: IF_LONG_OPTS( | 367 | //usage: IF_LONG_OPTS( |
338 | //usage: "\n --systz Set in-kernel timezone, correct system time" | 368 | //usage: "\n --systz Set in-kernel timezone, correct system time" |
369 | //usage: "\n if RTC is kept in local time" | ||
339 | //usage: ) | 370 | //usage: ) |
340 | //usage: "\n if hardware clock is in local time" | 371 | //usage: "\n -f DEV Use specified device (e.g. /dev/rtc2)" |
341 | //usage: "\n -u Assume hardware clock is kept in UTC" | 372 | //usage: "\n -u Assume RTC is kept in UTC" |
342 | //usage: IF_LONG_OPTS( | 373 | //usage: "\n -l Assume RTC is kept in local time" |
343 | //usage: "\n --localtime Assume hardware clock is kept in local time" | 374 | //usage: "\n (if neither is given, read from "ADJTIME_PATH")" |
344 | //usage: ) | ||
345 | //usage: "\n -f FILE Use specified device (e.g. /dev/rtc2)" | ||
346 | 375 | ||
347 | //TODO: get rid of incompatible -t and -l aliases to --systz and --localtime | 376 | //TODO: get rid of incompatible -t alias to --systz? |
348 | 377 | ||
349 | #define HWCLOCK_OPT_LOCALTIME 0x01 | 378 | #define HWCLOCK_OPT_LOCALTIME 0x01 |
350 | #define HWCLOCK_OPT_UTC 0x02 | 379 | #define HWCLOCK_OPT_UTC 0x02 |
@@ -362,7 +391,7 @@ int hwclock_main(int argc UNUSED_PARAM, char **argv) | |||
362 | int utc; | 391 | int utc; |
363 | #if ENABLE_LONG_OPTS | 392 | #if ENABLE_LONG_OPTS |
364 | static const char hwclock_longopts[] ALIGN1 = | 393 | static const char hwclock_longopts[] ALIGN1 = |
365 | "localtime\0" No_argument "l" /* short opt is non-standard */ | 394 | "localtime\0" No_argument "l" |
366 | "utc\0" No_argument "u" | 395 | "utc\0" No_argument "u" |
367 | "show\0" No_argument "r" | 396 | "show\0" No_argument "r" |
368 | "hctosys\0" No_argument "s" | 397 | "hctosys\0" No_argument "s" |
@@ -372,12 +401,14 @@ int hwclock_main(int argc UNUSED_PARAM, char **argv) | |||
372 | ; | 401 | ; |
373 | #endif | 402 | #endif |
374 | opt = getopt32long(argv, | 403 | opt = getopt32long(argv, |
375 | "^lurswtf:" "\0" "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l", | 404 | "^""lurswtf:v" /* -v is accepted and ignored */ |
405 | "\0" | ||
406 | "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l", | ||
376 | hwclock_longopts, | 407 | hwclock_longopts, |
377 | &rtcname | 408 | &rtcname |
378 | ); | 409 | ); |
379 | 410 | ||
380 | /* If -u or -l wasn't given check if we are using utc */ | 411 | /* If -u or -l wasn't given, check if we are using utc */ |
381 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) | 412 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) |
382 | utc = (opt & HWCLOCK_OPT_UTC); | 413 | utc = (opt & HWCLOCK_OPT_UTC); |
383 | else | 414 | else |