Commit graph

187 commits

Author SHA1 Message Date
Sami Kerola
473ec35974 hwclock: remove bool type definition
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>
2017-08-30 11:21:56 +02:00
J William Piggott
e406be01b4 hwclock: for debugging print startup system time
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-08-24 18:49:11 -04:00
J William Piggott
e5cb8d4dfe hwclock: refactor set_system_clock()
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-08-24 18:48:47 -04:00
J William Piggott
c8f64f94f3 hwclock: update set_system_clock comments
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-08-24 18:30:39 -04:00
J William Piggott
b44dd522b4 hwclock: update set_system_clock debugging
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>
2017-08-24 18:30:39 -04:00
J William Piggott
3a7669aa8a hwclock: remove set_system_clock_timezone()
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>
2017-08-24 18:30:39 -04:00
J William Piggott
404fdd2ca4 hwclock: move systz into hctosys
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>
2017-08-24 18:30:39 -04:00
J William Piggott
88d2a1a312 hwclock: fix hclock_valid test and error messages
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>
2017-08-04 08:57:13 -04:00
J William Piggott
1ef6feb533 hwclock: correlate hclocktime instead of set_time.
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>
2017-08-04 08:53:44 -04:00
J William Piggott
ee723d2352 hwclock: fix RTC read logic
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>
2017-08-04 08:53:44 -04:00
J William Piggott
a218e2a83f hwclock: move drift correction and --predict
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>
2017-08-04 08:53:44 -04:00
J William Piggott
551e703401 hwclock: move rtc permissions test
Move the rtc permissions test below the systz call and
simplify it's 'if' test.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-08-04 08:53:44 -04:00
J William Piggott
4ba19a2f79 hwclock: move systz above init clocks read
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>
2017-08-04 08:53:44 -04:00
J William Piggott
0d7ffb9c85 hwclock: squash custom errno strings
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>
2017-07-31 16:10:47 -04:00
J William Piggott
fa5b4d45d5 hwclock: fix regression from c3ae785
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>
2017-07-19 20:48:10 -04:00
J William Piggott
62f22d912d hwclock: remove unused epoch_option
Also one whitespace fix.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-19 20:46:12 -04:00
J William Piggott
c26ddc568f hwclock: improve RTC epoch messages
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-16 08:41:54 -04:00
J William Piggott
f7599b4f86 hwclock: --epoch presence test fails
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>
2017-07-16 08:41:54 -04:00
J William Piggott
2b1aa08734 hwclock: sync one-liner descriptions
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>
2017-07-10 16:05:24 -04:00
J William Piggott
cb8e26cc59 hwclock: final usage() strings slice
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-10 16:02:08 -04:00
J William Piggott
57c45481fc hwclock: usage() use program_invocation_short_name
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-10 16:02:08 -04:00
J William Piggott
02777914d5 hwclock: remove from usage() FILE *out = stdout
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-10 16:02:08 -04:00
Ruediger Meier
f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
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>
2017-06-29 16:54:33 +02:00
Ruediger Meier
3eeaef995b hwclock: don't ifdef printf arguments
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>
2017-06-29 14:04:36 +02:00
Ruediger Meier
c3ae785433 misc: avoid some dead initialization warnings
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>
2017-06-29 14:04:25 +02:00
Ruediger Meier
b1a294c448 misc: introduce print_usage_help_options()
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>
2017-06-27 12:26:19 +02:00
Ruediger Meier
86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
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>
2017-06-26 14:38:24 +02:00
Karel Zak
dfdb1ca818 Merge branch 'fix-exit-codes' of https://github.com/rudimeier/util-linux
* '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
2017-06-26 13:47:04 +02:00
Ruediger Meier
778ca2a0d4 misc: fix xalloc.h related exit codes
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>
2017-06-22 22:40:27 +02:00
Ruediger Meier
0b2b32e8a7 misc: fix more strutils related exit codes
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>
2017-06-22 22:40:21 +02:00
J William Piggott
2cb89055c5 hwclock: add audit for --systz
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-21 20:37:41 -04:00
J William Piggott
32adac4c9e hwclock: remove unused optstring characters
getopt_long() opstring contained obsolete entries.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-21 20:37:41 -04:00
Karel Zak
3d27fdba59 hwclock: remove unwanted space before description
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-21 11:25:16 +02:00
J William Piggott
ba2cdc0c66 hwclock: remove unused stdarg.h
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:56:39 -04:00
J William Piggott
891b43432f hwclock: add --update-drift check
Only allow --update-drift for --set or --systohc

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:56:39 -04:00
J William Piggott
d4affe81bb hwclock: slice up the usage text
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:56:39 -04:00
J William Piggott
cc7cb070d9 hwclock: update --help content and grammar
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:55:08 -04:00
J William Piggott
36b2645405 hwclock: use RTC in help output
Switching between 'hardware clock' and 'RTC' is ambiguous.
RTC is used due to space constraints, so use it consistently.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:51:27 -04:00
J William Piggott
513bfbefa2 hwclock: add usage() functions heading
Make a functions heading, similar to the existing options heading.

* include/c.h: define USAGE_FUNCTIONS
* Documentation/boilerplate.c: add USAGE_FUNCTIONS
* sys-utils/hwclock.c add functions header to usage()

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:50:38 -04:00
J William Piggott
7d9a866d1b hwclock: update usage() FILE name
Use the util-linux standard file name instead of 'usageto'.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:15:05 -04:00
J William Piggott
064f776c37 hwclock: update usage() to util-linux style
Update usage() according to:
  Documentation/howto-usage-function.txt
  Documentation/boilerplate.c

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:15:05 -04:00
J William Piggott
ea298febb8 hwclock: remove dead code in usage()
Commit 677ec86 caused usage() to be called only by --help.

So remove the now dead code from usage().

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:15:04 -04:00
Sami Kerola
b1557fe981 misc: fix ggc-7 fallthrough warnings
(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 11:48:22 +02:00
Ruediger Meier
39ff5b34d3 hwclock: fix warning [-Winvalid-noreturn]
clang warned:

 CC       sys-utils/hwclock.o
../sys-utils/hwclock.c:1274:1: warning: function declared 'noreturn' should not return [-Winvalid-noreturn]

We have to move the noreturn attribute from the function definition
to the declaration.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-14 11:48:22 +02:00
Rasmus Villemoes
3752694299 hwclock: allow -l as alias for --localtime
For symmetry with --utc where a short form is already allowed, and to
make it easier to write scripts that will work with both util-linux'
and busybox' hwclock, make -l another spelling of
--localtime. (Busybox also understands --localtime, but only if it has
been compiled with long option support.)
2017-05-31 20:25:16 +02:00
J William Piggott
57415653a6 hwclock: use a consistent name for --predict
The predict function name is documented as '--predict', but the
code uses '--predict-hc'. This works okay, except that the
'mutually exclusive' error message prints the undocumented name.

* sys-utils/hwclock.c: rename 'predict-hc' to 'predict' so that
    it matches the man-page. This should not be a problem because
    'predict-hc' was never documented.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-26 23:19:56 -04:00
J William Piggott
019093776a hwclock: remove unneeded braces
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-26 23:19:56 -04:00
J William Piggott
142efd2406 hwclock: make clock test mode message consistent
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-26 23:19:56 -04:00
J William Piggott
66c83c1c7f hwclock: extra messages for debug only
Only print extra save_adjtime() messages in debug mode. This makes
the --test mode output consistent accross functions.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-26 23:19:56 -04:00
J William Piggott
d8949acaa7 hwclock: improve audit control
Move audit control to option parsing. This fixes non-alpha build
error and cleans up an unruly 'if' statement.

Having audit control in option parsing may also draw awareness to
the audit system when adding new functions, which could easily be
overlooked otherwise.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-18 22:39:05 -04:00