]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: --epoch presence test fails
authorJ William Piggott <elseifthen@gmx.com>
Fri, 14 Jul 2017 19:51:47 +0000 (15:51 -0400)
committerJ William Piggott <elseifthen@gmx.com>
Sun, 16 Jul 2017 12:41:54 +0000 (08:41 -0400)
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>
sys-utils/hwclock-rtc.c
sys-utils/hwclock.8.in
sys-utils/hwclock.c
sys-utils/hwclock.h

index b39a97055289ef504ac8fd069a266a87f9ec17d7..9d3e5b98312435c46b52165c99ac09f293c8ce66 100644 (file)
@@ -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."),
index fa8a19af6ea8bbdef3e9f82e89c830162847026a..b616e3f5e11841c77d11e0457b7b3329696acd75 100644 (file)
@@ -305,6 +305,9 @@ methods fail.  See the
 .BI \-\-epoch= year
 This option is required when using the
 .BR \%\-\-setepoch \ function.
+.RI "The minimum " year
+value is 1900. The maximum is system dependent
+.RB ( ULONG_MAX\ -\ 1 ).
 .
 .TP
 .BR \-f , \ \-\-rtc=\fIfilename\fR
index a3cd49a3846f71038e3e16334d85e77ea1b498e5..445d736358586cdafdf82e1b95db863a13d554f3 100644 (file)
@@ -78,7 +78,6 @@
 #include "nls.h"
 #include "optutils.h"
 #include "pathnames.h"
-#include "strutils.h"
 #include "hwclock.h"
 #include "timeutils.h"
 #include "env.h"
@@ -1179,13 +1178,13 @@ manipulate_epoch(const struct hwclock_control *ctl)
                        printf(_("Kernel is assuming an epoch value of %lu\n"),
                               epoch);
        } else if (ctl->setepoch) {
-               if (ctl->epoch_option == 0)
+               if (!ctl->epoch_option)
                        warnx(_
                              ("To set the epoch value, you must use the 'epoch' "
                               "option to tell to what value to set it."));
                else if (ctl->testing)
                        printf(_
-                              ("Not setting the epoch to %lu - testing only.\n"),
+                              ("Not setting the epoch to %s - testing only.\n"),
                               ctl->epoch_option);
                else if (set_epoch_rtc(ctl))
                        printf(_
@@ -1328,8 +1327,6 @@ int main(int argc, char **argv)
        };
        int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
 
-       strutils_set_exitcode(EX_USAGE);
-
        /* Remember what time we were invoked */
        gettimeofday(&startup_time, NULL);
 
@@ -1407,8 +1404,7 @@ int main(int argc, char **argv)
                        ctl.hwaudit_on = 1;
                        break;
                case OPT_EPOCH:
-                       ctl.epoch_option =      /* --epoch */
-                           strtoul_or_err(optarg, _("invalid epoch argument"));
+                       ctl.epoch_option = optarg;      /* --epoch */
                        break;
 #endif
                case OPT_NOADJFILE:
index d527fe31085a1a3323613d30fab2cbb05b2f3ed4..61be57ac7a2e9e34ab9087c5b6b3de6908129314 100644 (file)
@@ -20,7 +20,7 @@ struct hwclock_control {
        char *date_opt;
        char *adj_file_name;
 #if defined(__linux__) && defined(__alpha__)
-       unsigned long epoch_option;
+       char *epoch_option;
 #endif
 #ifdef __linux__
        char *rtc_dev_name;