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>
This commit is contained in:
Karel Zak 2019-10-07 12:57:43 +02:00
parent 6bebea1b13
commit b3fc2a3c33
2 changed files with 8 additions and 3 deletions

View File

@ -129,9 +129,12 @@ static int open_rtc(const struct hwclock_control *ctl)
printf(_("Trying to open: %s\n"), fls[i]);
rtc_dev_fd = open(fls[i], O_RDONLY);
if (rtc_dev_fd < 0
&& (errno == ENOENT || errno == ENODEV))
continue;
if (rtc_dev_fd < 0) {
if (errno == ENOENT || errno == ENODEV)
continue;
if (ctl->verbose)
warn(_("cannot open %s"), fls[i]);
}
rtc_dev_name = fls[i];
break;
}

View File

@ -940,8 +940,10 @@ static void determine_clock_access_method(const struct hwclock_control *ctl)
} else {
if (ctl->verbose)
printf(_("No usable clock interface found.\n"));
warnx(_("Cannot access the Hardware Clock via "
"any known method."));
if (!ctl->verbose)
warnx(_("Use the --verbose option to see the "
"details of our search for an access "