Commit Graph

43 Commits

Author SHA1 Message Date
Karel Zak 8335261c3d hwclock: check errno after strto..()
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-07-20 11:33:27 +02:00
Łukasz Stelmach c8650db343 hwclock: fix indentation
Fixes: 042f62dfc ("[clang-tidy] do not use else after return")
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
2021-03-16 14:23:48 +01:00
Karel Zak cf8c191738 hwclock: fix compiler warnings [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c: In function 'synchronize_to_clock_tick_rtc':
sys-utils/hwclock.c:169:28: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:24: note: 'now.tv_usec' was declared here
sys-utils/hwclock.c:168:28: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:24: note: 'now.tv_sec' was declared here
sys-utils/hwclock.c:169:28: warning: 'begin.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:17: note: 'begin.tv_usec' was declared here
sys-utils/hwclock.c:168:28: warning: 'begin.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:17: note: 'begin.tv_sec' was declared here

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-14 15:59:45 +01:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Karel Zak 68a2ade7ed hwclock: add SPDX-License-Identifier(s)
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-08 11:12:13 +01:00
Karel Zak b3fc2a3c33 hwclock: report rtc open() errors on --verbose
Let's be more verbose and provide real open() error to make
debugging easier on --verbose.

For example:

$ hwclock --verbose
hwclock from util-linux 2.34.193-6bebea-dirty
System Time: 1570445823.701266
Trying to open: /dev/rtc0
hwclock: cannot open /dev/rtc0: Permission denied          <---
No usable clock interface found.
hwclock: Cannot access the Hardware Clock via any known method.

Addresses: https://github.com/karelzak/util-linux/issues/879
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-07 12:57:43 +02:00
Sami Kerola f78a902174
hwclock: use monotonic time to measure how long setting time takes
Earlier gettimeofday() was affected by discontinuous jumps.  Measuring how
long time it takes to set time using function that effected by the very
thing being measured makes head spin.  Lets make this less confusing with
monotonic clock that ticks on without jumps.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-01-12 08:46:54 +00:00
Karel Zak 0dcb713f2e hwclock: rely on kernel for RTC_UIE_ON on Aplha and Sparc
It's kernel business to return EINVAL for unsupported RTC_UIE_ON. We
(userspace) should not make decisions about things that we do not
control.

If kernel is wrong then fix the kernel, don't hide the problem by
crazy ifdefs in userspace.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-03 13:08:21 +02:00
Karel Zak df4f1a6647 hwclock: add --delay <seconds>
* 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>
2018-07-18 13:59:15 +02:00
J William Piggott de4568f757 hwclock: rename --debug option to --verbose
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>
2018-01-17 13:29:11 +01:00
Karel Zak 800e447741 hwclock: revert ioctl test
This commit reverts 1d5cffa16a.

(I did this revert manually as there was another changes in the code
and git-revert does not work in this case.)

Addresses: https://github.com/karelzak/util-linux/issues/543
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-23 10:30:27 +01:00
J William Piggott c47a8f2a87 hwclock: remove sysexits.h
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>
2017-09-03 12:03:10 -04:00
J William Piggott 4a6f658cb2 hwclock: remove busywait tristate return status
The select() synchronization branch only returns success or
fail. There is no reason for the busywait branch to do more.
If synchronization fails for any reason then it must exit,
otherwise all drift correction operation will be invalid.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-08-04 08:53:45 -04:00
J William Piggott bbf12e45f8 hwclock: restore select() timeout warning
hwclock now exits on select(2) timeout so restore the warning.

Reverts commit ab8f402952
 and    commit efc4eaf422

Except use warnx(), because select() timeout does not set errno.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-08-04 08:53:45 -04:00
J William Piggott 0411a57e25 hwclock: remove custom errno string
Custom errno messages are unnecessary and problematic for translators.

The current messages are also too long, > 90 columns:
/dev/rtc0 does not have interrupt functions. Waiting in loop for time from \
/dev/rtc0 to change

Fixed:
ioctl(3, RTC_UIE_ON, 0): Inappropriate ioctl for device
Waiting in loop for time from /dev/rtc0 to change

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-31 16:10:47 -04:00
J William Piggott 1d5cffa16a hwclock: fix unimplemented ioctl test
The rtc driver has not returned EINVAL for unimplemented ioctls since
v2.5.8 in 2002. However, it does return it for other errors; making the
current test potentially problematic. Since 9f3d0fc util-linux assumes
kernel >= 2.6.0 so remove EINVAL as an ioctl test.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-31 16:10:47 -04:00
J William Piggott cbc36f7903 hwclock: squash custom errno strings
warn() appends ENOENT as: No such file or directory

The custom string is unnecessary and problematic for translators.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-31 16:10:47 -04:00
J William Piggott f613c3c2ed hwclock: improve RTC epoch messages
Make consistent and improve messages in get_epoch_rtc()
and set_epoch_rtc().

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-07-16 08:41:54 -04:00
J William Piggott 1705066af5 hwclock: remove dead ioctl check
The epoch ioctls test hasn't been valid for 20 years (v2.1.88).
RTC has returned ENOTTY for unimplemented ioctls for 15 years.

The check is made for RTC_EPOCH_SET, but not for RTC_EPOCH_READ.
They were both implemented at the same time.

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 9c7234bc32 hwclock: fix whitespace in hwclock-rtc.c
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-10 14:50:32 -04:00
J William Piggott af68bd014a hwclock: remove unused 'silent' arg
The 'silent' argument for get_epoch_rtc() was used
to silence error messages when querying the rtc
driver for an alpha epoch while using cmos direct
access. Alpha cmos has since been removed so
'silent' is no longer used.

* sys-utils/hwclock.h: remove 'silent' argument
* sys-utils/hwclock.c: same
* sys-utils/hwclock-rtc.c: same

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-03-31 10:04:53 -04:00
J William Piggott 1811900a91 hwclock-rtc.c: try the 'new' rtc class first
* sys-utils/hwclock-rtc.c: try to open the 'new' rtc class driver first.
* sys-utils/hwclock.8.in: document this.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-03-23 16:14:01 -04:00
Sami Kerola c9a86ff664
hwclock: remove trailing dot from messages that include system error message
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 926ffe7451
hwclock: fix rtc atexit registration
Commit 27f9db17bd missed a minus sign from
comparison.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola fc35f2db79
hwclock: try RTCGET and RTCSET only when normal rtc fails
The RTCGET and RTCSET are in use for sparcs with sbus, so try them as
fallback rather than always.

Reference: https://github.com/torvalds/linux/blob/master/fs/compat_ioctl.c#L967-L974
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 4bfd519eee
hwclock: stream line synchronize_to_clock_tick_rtc()
Flip if clauses to hit common case first.  This should be easier and quicker
to read and run.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola bd0786895d
hwclock: improve coding style
Make string constants to be symbolical declarations.  Use longer variable
name for rtc and cmos function pointer values.  Exclude code that is
architecture specific with preprocessor directives.  And remove message
duplication.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 067b60280a
hwclock: add debugging to open_rtc()
Earlier when open_rtc() returned -1 the char *rtc_dev_name end up having
NULL that made it unsuitable to be used in error message.  Now one can debug
what paths the open_rtc() tries to use when one has to debug why 'cannot
open rtc device' happen.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 0f32118e70
hwclock: use symbolic magic values passed in between functions
The manipulate_clock() is seeing return value from
busywait_for_rtc_clock_tick().

And the get_permissions_cmos() can see i386_iopl() return value.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola c6ea9ef6cb
hwclock: remove dead code and other minor fixes
Use #ifdef rather than #if to avoid undefined preprocessor identifier
warning.

Remove dead code.  The #if 0 ensured the code has not been used for long
time, which is good because the linux/mc146818rtc.h is not been part of
user-api for long time.

Value of the adjtime_p->last_calib_time is checked if it has value of zero,
so testing none-zero bit later is necessarily true, and therefore does not
need to be checked.

And at the and remove unnecessary boolean variable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 8f729d60fa
hwclock: move error messages to determine_clock_access_method()
This makes main() a little bit shorter.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 336f7c5f68
hwclock: move command-line options to control structure
The control structure is read-only everywhere else but in main().  Almost
all changes are about how variables are referred, with one exception.  Calls
to read_adjtime() from manipulate_clock() and compare_clock() are moved to
main().  This way it is possible to keep variable that tells if hwclock is
using UTC-0 be part of control structure.

Changes within #ifdef __alpha__ segments were tested by flipping the
preprocessor directivive otherway around and getting good compilaton all the
way to the point where linking on none-alpha system failed.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Boris Egorov faebeb86e5 hwclock: fix format specifier [cppcheck]
[sys-utils/hwclock-rtc.c:435]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'unsigned long'.
2016-01-19 12:59:12 +06:00
Boris Egorov e3ca1312a2 sys-utils/disk-utils/lib: fix printf format types [cppcheck]
Fix 'invalidPrintfArgType' cppcheck warnings

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-25 12:08:45 +02:00
J William Piggott 9fb890c3c5 hwclock: remove dead code
Removes never used #ifdef dead code.

Reported-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2015-04-21 16:46:23 -04:00
J William Piggott efc4eaf422 hwclock: regression fix
Commit ab8f402952 regression
where synchronize_to_clock_tick_rtc() only returns the correct
value for a select() time out if using debug mode. This caused
hwclock to have invalid output when select() timed out in
normal mode.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2015-04-21 16:43:41 -04:00
Benno Schulenberg b2d97db8c8 hwclock: internationalizing the message of the used interface
In addition, do it in a single sentence instead of in two fragments.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-02-10 18:41:55 +01:00
Karel Zak 5724b74dd8 hwclock: cleanup _() usage in synchronize_to_clock_tick_rtc()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-21 08:56:15 +01:00
Karel Zak ab8f402952 hwclock: don't confuse users with select() timeout warning
Reported-by: Daniel Drake <dsd@laptop.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-21 08:51:22 +01:00
Karel Zak 72fc8ca062 hwclock: wait time in hwclock is not long enough for some ARM devices
On Sun, Sep 16, 2012 at 02:11:48PM +0800, Queen Adam wrote:
> I'm using Archlinux ARM for my Melo A100 box.
> The hwclock always timeout when using select() in rtc.c.
>
> After I change the timeout from 5 to 10, the problem is solved.
>
> In fact the timeout in my ARM box seems only to be a little larger
> than 5s.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-21 12:05:12 +02:00
Sami Kerola 289dcc9023 translation: unify file open error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Karel Zak c7f753901f build-sys: move hwclock to sys-utils/
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26 20:48:23 +02:00