Merge branch '170711' of github.com:jwpi/util-linux

* '170711' of github.com:jwpi/util-linux:
  hwclock: improve RTC epoch messages
  hwclock: improve RTC epoch messages
  hwclock: remove dead ioctl check
  hwclock: --epoch presence test fails
This commit is contained in:
Karel Zak 2017-07-17 12:02:24 +02:00
commit e0a88864a7
4 changed files with 33 additions and 54 deletions

View File

@ -403,24 +403,21 @@ int get_epoch_rtc(const struct hwclock_control *ctl, unsigned long *epoch_p)
rtc_fd = open_rtc(ctl);
if (rtc_fd < 0) {
if (errno == ENOENT)
warnx(_
("To manipulate the epoch value in the kernel, we must "
"access the Linux 'rtc' device driver via the device special "
"file. This file does not exist on this system."));
warnx(_("%s does not exist."), rtc_dev_name);
else
warn(_("cannot open rtc device"));
warn(_("cannot open %s"), rtc_dev_name);
return 1;
}
if (ioctl(rtc_fd, RTC_EPOCH_READ, epoch_p) == -1) {
warn(_("ioctl(RTC_EPOCH_READ) to %s failed"), rtc_dev_name);
warn(_("ioctl(%d, RTC_EPOCH_READ, epoch_p) to %s failed"),
rtc_fd, rtc_dev_name);
return 1;
}
if (ctl->debug)
printf(_("we have read epoch %lu from %s "
"with RTC_EPOCH_READ ioctl.\n"), *epoch_p,
rtc_dev_name);
printf(_("ioctl(%d, RTC_EPOCH_READ, epoch_p) to %s succeeded.\n"),
rtc_fd, rtc_dev_name);
return 0;
}
@ -431,45 +428,34 @@ 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;
}
rtc_fd = open_rtc(ctl);
if (rtc_fd < 0) {
if (errno == ENOENT)
warnx(_
("To manipulate the epoch value in the kernel, we must "
"access the Linux 'rtc' device driver via the device special "
"file. This file does not exist on this system."));
warnx(_("%s does not exist."), rtc_dev_name);
else
warn(_("cannot open rtc device"));
warn(_("cannot open %s"), rtc_dev_name);
return 1;
}
if (ioctl(rtc_fd, RTC_EPOCH_SET, epoch) == -1) {
warn(_("ioctl(%d, RTC_EPOCH_SET, %lu) to %s failed"),
rtc_fd, epoch, rtc_dev_name);
return 1;
}
if (ctl->debug)
printf(_("setting epoch to %lu "
"with RTC_EPOCH_SET ioctl to %s.\n"), ctl->epoch_option,
rtc_dev_name);
if (ioctl(rtc_fd, RTC_EPOCH_SET, ctl->epoch_option) == -1) {
if (errno == EINVAL)
warnx(_("The kernel device driver for %s "
"does not have the RTC_EPOCH_SET ioctl."),
rtc_dev_name);
else
warn(_("ioctl(RTC_EPOCH_SET) to %s failed"),
rtc_dev_name);
return 1;
}
printf(_("ioctl(%d, RTC_EPOCH_SET, %lu) to %s succeeded.\n"),
rtc_fd, epoch, rtc_dev_name);
return 0;
}

View 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

View 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"
@ -1173,23 +1172,17 @@ manipulate_epoch(const struct hwclock_control *ctl)
unsigned long epoch;
if (get_epoch_rtc(ctl, &epoch))
warnx(_
("Unable to get the epoch value from the kernel."));
warnx(_("unable to read the RTC epoch."));
else
printf(_("Kernel is assuming an epoch value of %lu\n"),
epoch);
printf(_("The RTC epoch is set to %lu.\n"), epoch);
} else if (ctl->setepoch) {
if (ctl->epoch_option == 0)
warnx(_
("To set the epoch value, you must use the 'epoch' "
"option to tell to what value to set it."));
if (!ctl->epoch_option)
warnx(_("--epoch is required for --setepoch."));
else if (ctl->testing)
printf(_
("Not setting the epoch to %lu - testing only.\n"),
printf(_("Test mode: epoch was not set to %s.\n"),
ctl->epoch_option);
else if (set_epoch_rtc(ctl))
printf(_
("Unable to set the epoch value in the kernel.\n"));
warnx(_("unable to set the RTC epoch."));
}
}
#endif /* __linux__ __alpha__ */
@ -1328,8 +1321,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 +1398,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:

View 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;