]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock, rtcwake: hint about uninitialized RTC on EINVAL
authorKarel Zak <kzak@redhat.com>
Wed, 24 Jun 2026 11:29:16 +0000 (13:29 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 24 Jun 2026 11:29:16 +0000 (13:29 +0200)
Some RTC drivers (e.g., rtc-nxp-bbnsm) return EINVAL from
RTC_RD_TIME when the hardware time counter has never been
initialized. Print a hint so users know the likely cause rather
than just seeing "Invalid argument".

Addresses: https://github.com/util-linux/util-linux/pull/4376

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/hwclock-rtc.c
sys-utils/rtcwake.c

index f8518c30c7412ca7945960c6ffa1ac66b2e048e7..1b82b77b4772803dd93f77dbbdb362f431f5e2a0 100644 (file)
@@ -157,8 +157,11 @@ static int do_rtc_read_ioctl(int rtc_fd, struct tm *tm)
        rc = ioctl(rtc_fd, RTC_RD_TIME, &rtc_tm);
 
        if (rc == -1) {
+               int errsv = errno;
                warn(_("ioctl(RTC_RD_TIME) to %s to read the time failed"),
                        rtc_dev_name);
+               if (errsv == EINVAL)
+                       warnx(_("RTC may not be initialized"));
                return -1;
        }
 
index ad5135644bedd16987f7e20c4e1ebb8932661996..0a3bf8e059a610c8f68da2129040e899be817472 100644 (file)
@@ -174,7 +174,10 @@ static int get_basetimes(struct rtcwake_control *ctl, int fd)
         * precisely (+/- a second) as we can read them.
         */
        if (ioctl(fd, RTC_RD_TIME, &rtc) < 0) {
+               int errsv = errno;
                warn(_("read rtc time failed"));
+               if (errsv == EINVAL)
+                       warnx(_("RTC may not be initialized"));
                return -1;
        }