summaryrefslogtreecommitdiffstats
path: root/sys-utils/hwclock-rtc.c
diff options
context:
space:
mode:
authorJ William Piggott2017-07-14 21:51:47 +0200
committerJ William Piggott2017-07-16 14:41:54 +0200
commitf7599b4f86f0db5856770fcdaeb599b76ea64b64 (patch)
tree6eaec6e681b6f35a7073724031601602d8ea32e7 /sys-utils/hwclock-rtc.c
parentlibfdisk: make fdisk compliant to UEFI/GPT specification on PMBR (diff)
downloadkernel-qcow2-util-linux-f7599b4f86f0db5856770fcdaeb599b76ea64b64.tar.gz
kernel-qcow2-util-linux-f7599b4f86f0db5856770fcdaeb599b76ea64b64.tar.xz
kernel-qcow2-util-linux-f7599b4f86f0db5856770fcdaeb599b76ea64b64.zip
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>
Diffstat (limited to 'sys-utils/hwclock-rtc.c')
-rw-r--r--sys-utils/hwclock-rtc.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/sys-utils/hwclock-rtc.c b/sys-utils/hwclock-rtc.c
index b39a97055..9d3e5b983 100644
--- a/sys-utils/hwclock-rtc.c
+++ b/sys-utils/hwclock-rtc.c
@@ -431,15 +431,13 @@ int get_epoch_rtc(const struct hwclock_control *ctl, unsigned long *epoch_p)
int set_epoch_rtc(const struct hwclock_control *ctl)
{
int rtc_fd;
+ unsigned long epoch;
- if (ctl->epoch_option < 1900) {
- /* kernel would not accept this epoch value
- *
- * Bad habit, deciding not to do what the user asks just
- * because one believes that the kernel might not like it.
- */
- warnx(_("The epoch value may not be less than 1900. "
- "You requested %ld"), ctl->epoch_option);
+ epoch = strtoul(ctl->epoch_option, NULL, 10);
+
+ /* There were no RTC clocks before 1900. */
+ if (epoch < 1900 || epoch == ULONG_MAX) {
+ warnx(_("invalid epoch '%s'."), ctl->epoch_option);
return 1;
}
@@ -457,10 +455,9 @@ int set_epoch_rtc(const struct hwclock_control *ctl)
if (ctl->debug)
printf(_("setting epoch to %lu "
- "with RTC_EPOCH_SET ioctl to %s.\n"), ctl->epoch_option,
+ "with RTC_EPOCH_SET ioctl to %s.\n"), epoch,
rtc_dev_name);
-
- if (ioctl(rtc_fd, RTC_EPOCH_SET, ctl->epoch_option) == -1) {
+ if (ioctl(rtc_fd, RTC_EPOCH_SET, epoch) == -1) {
if (errno == EINVAL)
warnx(_("The kernel device driver for %s "
"does not have the RTC_EPOCH_SET ioctl."),