summaryrefslogtreecommitdiffstats
path: root/sys-utils/hwclock.c
Commit message (Collapse)AuthorAgeFilesLines
* hwclock: use CMOS clock only if availableCarlos Santos2019-07-151-0/+2
| | | | | | | | | | | | - Add --disable-hwclock-cmos configuration argument - Add USE_HWCLOCK_CMOS (enabled by default for i386/x86_64) - Add define(USE_HWCLOCK_CMOS) - Compile hwclock-cmos.c only if USE_HWCLOCK_CMOS is true - Remove all unnecessary #ifdefs from hwclock-cmos.c - Add #ifdef USE_HWCLOCK_CMOS around the determine_clock_access_method() call in hwclock.c Signed-off-by: Carlos Santos <unixmania@gmail.com>
* hwclock: don't use uninitialized value [coverity scan]Karel Zak2019-05-231-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* various: fix 'uninitialized when used' warnings [clang]Sami Kerola2019-02-181-1/+1
| | | | | | | This change fixes "warning: variable 'var' may be uninitialized when used here [-Wconditional-uninitialized]" warnings reported in various files. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* hwclock: add --delay <seconds>Karel Zak2018-07-181-6/+70
| | | | | | | | | | | * add command line option --delay <seconds> * read RTC type from /sys/class/rtc/rtc<N>/name * default to 0.5 (500ms) for rtc_cmos or when RTC type is impossible determine; otherwise delay is 0. Signed-off-by: Karel Zak <kzak@redhat.com>
* hwclock: add --ul-debug implementing debug.hJ William Piggott2018-01-221-16/+33
| | | | | | | | | | | | | | | | | Undocumented at this time, because it is a skeleton implementation. More debugging points are to be added after refactoring is complete, or ad hoc in the mean time. When fully implemented, enough time may have passed that the deprecated --debug could be used to replace --ul-debug. [kzak@redhat.com: - use __UL_INIT_DEBUG_FROM_STRING() to initialize the mask - add hwclock_init_debug()] Coauthored-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: J William Piggott <elseifthen@gmx.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* hwclock: rename --debug option to --verboseJ William Piggott2018-01-171-35/+38
| | | | | | | | | Warn on --debug; do not fallthrough because the message is lost in the verbose output. Coauthored-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/timeutils.c: warn format_iso_time() overflowJ William Piggott2017-12-101-3/+2Star
| | | | | | | | | Print a message when the format_iso_time() buffer is exceeded, because there is more than one type of failure that returns -1. Also remove the corresponding message from hwclock.c. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: fix debug regressionJ William Piggott2017-11-181-1/+1
| | | | | | | | | | | | | | | | commit f0a0ce7 makes debug mode implicit for the --test option. Using the previous command syntax of --test and --debug together invokes the undocumented Level 2 debugging when setting the RTC. This can cause many thousands of lines of output like: 1510967983.499968 < 1510967983.500000 (-0.000032) Fix: bump Level 2 debugging to Level 9, just before the other undocumented Level 10. This makes it improbable for the development debug levels to be accessed unintentionally. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: use reentrant time conversion functionsJ William Piggott2017-11-171-5/+5
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/timeutils: add common ISO timestamp masksJ William Piggott2017-11-101-4/+2Star
| | | | | | | | | | | | | | | | | | | | | | * Start the ISO format flags at bit 0 instead of bit 1. * Remove unnecessary _8601 from ISO format flag names to avoid line wrapping and to ease readability. * ISO timestamps have date-time-timzone in common, so move the TIMEZONE flag to bit 2 causing all timestamp masks to have the first three bits set and the last four bits as timestamp 'options'. * Change the 'SPACE' flag to a 'T' flag, because it makes the code and comments more concise. * Add common ISO timestamp masks. * Implement the ISO timestamp masks in all applicable code using the strxxx_iso() functions. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/timeutils: add get_gmtoff()J William Piggott2017-11-101-7/+1Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new function returns the GMT offset relative to its argument. It is used in this patch to fix two bugs: 1) On platforms that the tm struct excludes tm_gmtoff, hwclock assumes a one hour DST offset. This can cause an incorrect kernel timezone setting. For example: Master branch tested with tm_gmtoff illustrates the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494204.192398, -660) Master branch tested without tm_gmtoff has an incorrect offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494249.193852, -690) Patched tested without tm_gmtoff has the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494260.194208, -660) 2) ISO 8601 'extended' format requires all time elements to use a colon (:). Current invalid ISO 8601: $ hwclock 2017-10-08 16:25:17.895462-0400 Patched: $ hwclock 2017-10-08 16:25:34.141895-04:00 Also required by this change: login-utils/last.c: increase ISO out_len and in_len by one to accommodate the addition of the timezone colon. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: add iso-8601 overflow checkJ William Piggott2017-11-101-6/+9
| | | | | | | | | | | | | | | | | | | | | | | hwclock wasn't testing for strtimeval_iso() truncation: /sbin/hwclock --utc --noadjfile --predict --date '7982 years'; echo $? 9999-09-25 19:33:01.000000-0400 0 /sbin/hwclock --utc --noadjfile --predict --date '7983 years'; echo $? 10000-09-25 19:33:10.000000- 0 Patched: ./hwclock --utc --noadjfile --predict --date '7982 years'; echo $? 9999-09-25 19:22:15.000000-0400 0 ./hwclock --utc --noadjfile --predict --date '7983 years'; echo $? hwclock: iso-8601 format truncated 1 Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: make debug implicit for test mode.J William Piggott2017-09-211-1/+2
| | | | | | | Calling --test without --debug is not useful, so make it implicit. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: exit bug fix and single test mode messageJ William Piggott2017-09-211-38/+23Star
| | | | | | | | Bug fix: hwclock returns success when saving /etc/adjtime fails. Remove redundant test mode messages. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: add -a that is short of --adjust to manual page and usageSami Kerola2017-09-051-2/+2
| | | | | | In same go use -V as return value of --version from getopts_long(). Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* hwclock: update usage()J William Piggott2017-09-051-1/+1
| | | | | | Improve usage strings for debug and version. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: close hwaudit_fd unconditionallyJ William Piggott2017-09-031-1/+1
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: don't always use hwclock_exitJ William Piggott2017-09-031-7/+7
| | | | | | | | Special exit handling is not wanted for usage() or bad command syntax. For example we do not want to audit: hwclock --set --date foo Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: remove sysexits.hJ William Piggott2017-09-031-45/+23Star
| | | | | | | | | | | | | sysexits.h was introduced in v2.11t prior to util-linux-ng, with the HISTORY entry: * hwclock: minor polishing. So there was no specific issue solved by adding it. Its use was never documented so it should be safe to remove. Also, fix return values being used for the exit status that were not magic constants (portability issue). Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: remove bool type definitionSami Kerola2017-08-301-16/+19
| | | | | | | | | Use plain int instead of type defining it to a boolean, and use numbers to signify true or false as we do everywhere else in this source tree. And in hwclock-cmos.c file booleans weren't even needed, to the related code is removed. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* hwclock: for debugging print startup system timeJ William Piggott2017-08-251-1/+4
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: refactor set_system_clock()J William Piggott2017-08-251-11/+6Star
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: update set_system_clock commentsJ William Piggott2017-08-251-15/+27
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: update set_system_clock debuggingJ William Piggott2017-08-251-4/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | Update debug messages for a combined --systz and --hctosys in the set_system_clock function. New debug messages: hwclock --test -D --systz --localtime Calling settimeofday(NULL, 240) to warp System time. Test mode: clock was not changed hwclock --test -D --systz --utc Calling settimeofday(NULL, 0) to lock the warp function. Calling settimeofday(NULL, 240) to set the kernel timezone. Test mode: clock was not changed hwclock --test -D --hctosys --utc Calling settimeofday(1502239269.733639, 240) Test mode: clock was not changed hwclock --test -D --hctosys --localtime Calling settimeofday(NULL, 240) to set persistent_clock_is_local. Calling settimeofday(1502253708.200200, 240) Test mode: clock was not changed Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: remove set_system_clock_timezone()J William Piggott2017-08-251-89/+0Star
| | | | | | | Remove set_system_clock_timezone() because the previous patch moved its functionality into set_system_clock(). Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: move systz into hctosysJ William Piggott2017-08-251-3/+9
| | | | | | | | | | | | | | | | The set_system_clock_timezone() function is nearly identical to set_system_clock(). Three additional statements are required to include systz in hctosys. This patch is intentionally incomplete to make reviewing the actual required changes easier. Other patches in this set will: * remove set_system_clock_timezone() * fix messages and debugging * fix comments * and finally refactor set_system_clock() Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: fix hclock_valid test and error messagesJ William Piggott2017-08-041-94/+53Star
| | | | | | | | | | | | | Every hwclock operation that requires reading the RTC, tests hclock_valid and prints a different warning. This redundancy is unnecessary. Move the warning to the RTC read block (the test was moved in a previous patch in this set). This reduces function arguments and is a significant code clean up. It will also benefit the translators. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: correlate hclocktime instead of set_time.J William Piggott2017-08-041-9/+13
| | | | | | | | | | Correlate hclocktime with set_time instead of the other way around, because set_time is used for timestamps in the adjtime file so it needs to be unadulterated. Also create var startup_hclocktime for correlated time. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: fix RTC read logicJ William Piggott2017-08-041-23/+15Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Over the past decade a few commits for a corner case problem have left the RTC read branch in a bad place. The problem was: when a corrupted RTC could not be read, then it also could not be reset, because hwclock would error out due to the RTC read failure. 2.15-rc1 commit 3b96a7a Aug 9 2008 2.19-rc1 commit 5606df5 Dec 29 2010 2.23-rc1 commit ab8f402 Mar 21 2013 The first fix was to ignore a synchronization timeout only for the busywait branch. Two and a half years later a commit describing the same problem took a little more heavy-handed approach by ignoring all synchronization failures and the RTC read after it, for both of the RTC set functions. Because the previous fix also ignored the select() branch timeout it caused a bogus warning. The chosen workaround for that was to only print the select() timeout message in debug mode (this is reverted by another patch). The problem with these fixes is that we cannot just ignore the synchronization timeout like that, because then the drift correction operations will be invalid. The original logic was correct; we must exit when synchronization fails. Another problem is that now there are statements between the timing-critical synchronize-read-timestamp trio (which were also in the wrong order, but that part of the problem goes back further in history). The solution is to skip the RTC read block completely for the RTC set functions when not also using the --update-drift option. If we are updating the drift correction factor during a set function then we must synchronize and read the RTC. Otherwise reading the RTC is not needed. Anyone trying to set a corrupt RTC should not be using --update-drift, because the resulting drift correction factor would be invalid. Using this approach has the added benefit of significantly reducing system shutdown time when not using --update-drift: time ./hwclock --test --systohc; time ./hwclock-master --test --systohc Test mode: clock was not changed real 0m0.072s user 0m0.066s sys 0m0.003s Test mode: clock was not changed real 0m1.000s user 0m0.169s sys 0m0.005s I've see differences as high as 1.518 seconds. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: move drift correction and --predictJ William Piggott2017-08-041-26/+31
| | | | | | | | | | | | Move the predict branch above the RTC read branch. Move drift correction into the RTC read branch, because it requires an accurate RTC read, and it needs to be skipped for operations that do not require an RTC read. Simplify the RTC read branch test. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: move rtc permissions testJ William Piggott2017-08-041-3/+3
| | | | | | | Move the rtc permissions test below the systz call and simplify it's 'if' test. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: move systz above init clocks readJ William Piggott2017-08-041-3/+4
| | | | | | | The systz option is all about speed, so move it to the top and simplify the init clocks read test. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: squash custom errno stringsJ William Piggott2017-07-311-26/+6Star
| | | | | | | | | | | | | | | | | | | | | | | | | hwclock previously used printf for custom errno messages. Later they were converted to use warn(), but were not squashed. One of the reasons for warn and errno is to avoid making translators deal with a multitude custom strings. Also the custom strings are incorrect: hwclock --hctosys hwclock: Must be superuser to set system clock. Unable to set system clock. We do not know what the system permissions are set to. The correct response is to simply say permission was denied; as the default errno string does. The second line is redundant and just adds noise the code and to logs. Patched: hwclock --hctosys hwclock: settimeofday() failed: Operation not permitted Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: fix regression from c3ae785J William Piggott2017-07-201-3/+3
| | | | | | | | | | | | hwclock --get foo hwclock: 3 too many arguments given Fixed: hwclock --get foo hwclock: 1 too many arguments given Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: remove unused epoch_optionJ William Piggott2017-07-201-1/+1
| | | | | | Also one whitespace fix. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: improve RTC epoch messagesJ William Piggott2017-07-161-11/+5Star
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: --epoch presence test failsJ William Piggott2017-07-161-7/+3Star
| | | | | | | | | | | | | | hwclock --setepoch --epoch 0 Will warn that the epoch option is required. The --epoch presence test is made on its argument after it is converted to an integer. This means any value it can be tested for, can also be given as an input. So make the conversion after the presence test, like the --date option does. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: sync one-liner descriptionsJ William Piggott2017-07-101-1/+1
| | | | | | | | | | | Make whatisdb/manpage and usage() one-line descriptions match. Also update the description; hwclock has evolved into much more than reading and setting the Hardware Clock. It also sets the System Clock, warps the System Clock, sets the kernel time configurations, and more. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: final usage() strings sliceJ William Piggott2017-07-101-1/+2
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: usage() use program_invocation_short_nameJ William Piggott2017-07-101-3/+3
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: remove from usage() FILE *out = stdoutJ William Piggott2017-07-101-32/+31Star
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* hwclock: don't ifdef printf argumentsRuediger Meier2017-06-291-2/+3
| | | | | | | | | | | | | | | | | | This may fails if printf() is macro, introduced in cc7cb070. clang compiler warnings: CC sys-utils/hwclock.o ../sys-utils/hwclock.c:1228:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive] #ifdef __linux__ ^ ../sys-utils/hwclock.c:1230:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive] #endif ^ 2 warnings generated. CC: J William Piggott <elseifthen@gmx.com> Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: avoid some dead initialization warningsRuediger Meier2017-06-291-4/+1Star
| | | | | | | | | | | | | | | | | | | | | Clang analyzer warnings: Dead store, Dead initialization: lib/mbsedit.c:154:8: warning: Value stored to 'in' during its initialization is never read char *in = (char *) &c; ^~ ~~~~~~~~~~~ misc-utils/findmnt-verify.c:129:14: warning: Value stored to 'cn' during its initialization is never read const char *cn = tgt; ^~ ~~~ Dead store, Dead increment: sys-utils/hwclock.c:1461:2: warning: Value stored to 'argv' is never read argv += optind; ^ ~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: cosmetics, remove argument from usage(FILE*)Ruediger Meier2017-06-261-2/+3
| | | | | | | | | | | | | | This patch is trivial and changes nothing, because we were always using usage(stdout) Now all our usage() functions look very similar. If wanted we could auto-generate another big cosmetical patch to remove all the useless "FILE *out" constants and use printf and puts rather than their f* friends. Such patch could be automatically synchronized with the translation project (newlines!) to not make the translators sick. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* Merge branch 'fix-exit-codes' of https://github.com/rudimeier/util-linuxKarel Zak2017-06-261-0/+3
|\ | | | | | | | | | | | | | | | | * 'fix-exit-codes' of https://github.com/rudimeier/util-linux: misc: fix optutils.h related exit codes misc: fix xalloc.h related exit codes misc: fix more strutils related exit codes lib: fix strutils.h, remove STRTOXX_EXIT_CODE misc: fix some broken exit codes
| * misc: fix xalloc.h related exit codesRuediger Meier2017-06-221-0/+1
| | | | | | | | | | | | | | | | | | Found by: grep -L "XALLOC_EXIT_CODE" $(grep -l "xalloc\.h" \ $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c")) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
| * misc: fix more strutils related exit codesRuediger Meier2017-06-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Found by grep: grep -l "\bEXIT_\|exit *( *[0-9][0-9] *)\|strutils\.h" $(grep -L \ strutils_set_exitcode $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c")) The Command shows also some false positives (fstrim.c, context_mount.c, ...) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>