]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: try RTCGET and RTCSET only when normal rtc fails
authorSami Kerola <kerolasa@iki.fi>
Tue, 26 Jul 2016 09:52:15 +0000 (10:52 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sat, 4 Feb 2017 23:39:38 +0000 (23:39 +0000)
The RTCGET and RTCSET are in use for sparcs with sbus, so try them as
fallback rather than always.

Reference: https://github.com/torvalds/linux/blob/master/fs/compat_ioctl.c#L967-L974
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/hwclock-rtc.c

index ba18823135fa14ec4f91884a8d383e20f47a09e3..fa5e07b118bc930bd6e43e1c2e9bf520bf0994e7 100644 (file)
@@ -158,28 +158,31 @@ static int do_rtc_read_ioctl(int rtc_fd, struct tm *tm)
 {
        int rc = -1;
        char *ioctlname;
-
 #ifdef __sparc__
        /* some but not all sparcs use a different ioctl and struct */
        struct sparc_rtc_time stm;
+#endif
+
+       ioctlname = "RTC_RD_TIME";
+       rc = ioctl(rtc_fd, RTC_RD_TIME, tm);
 
-       ioctlname = "RTCGET";
-       rc = ioctl(rtc_fd, RTCGET, &stm);
-       if (rc == 0) {
-               tm->tm_sec = stm.sec;
-               tm->tm_min = stm.min;
-               tm->tm_hour = stm.hour;
-               tm->tm_mday = stm.dom;
-               tm->tm_mon = stm.month - 1;
-               tm->tm_year = stm.year - 1900;
-               tm->tm_wday = stm.dow - 1;
-               tm->tm_yday = -1;       /* day in the year */
+#ifdef __sparc__
+       if (rc == -1) {         /* sparc sbus */
+               ioctlname = "RTCGET";
+               rc = ioctl(rtc_fd, RTCGET, &stm);
+               if (rc == 0) {
+                       tm->tm_sec = stm.sec;
+                       tm->tm_min = stm.min;
+                       tm->tm_hour = stm.hour;
+                       tm->tm_mday = stm.dom;
+                       tm->tm_mon = stm.month - 1;
+                       tm->tm_year = stm.year - 1900;
+                       tm->tm_wday = stm.dow - 1;
+                       tm->tm_yday = -1;       /* day in the year */
+               }
        }
 #endif
-       if (rc == -1) {         /* no sparc, or RTCGET failed */
-               ioctlname = "RTC_RD_TIME";
-               rc = ioctl(rtc_fd, RTC_RD_TIME, tm);
-       }
+
        if (rc == -1) {
                warn(_("ioctl(%s) to %s to read the time failed"),
                        ioctlname, rtc_dev_name);
@@ -334,8 +337,11 @@ static int set_hardware_clock_rtc(const struct hwclock_control *ctl,
 
        rtc_fd = open_rtc_or_exit(ctl);
 
+       ioctlname = "RTC_SET_TIME";
+       rc = ioctl(rtc_fd, RTC_SET_TIME, new_broken_time);
+
 #ifdef __sparc__
-       {
+       if (rc == -1) {         /* sparc sbus */
                struct sparc_rtc_time stm;
 
                stm.sec = new_broken_time->tm_sec;
@@ -350,10 +356,6 @@ static int set_hardware_clock_rtc(const struct hwclock_control *ctl,
                rc = ioctl(rtc_fd, RTCSET, &stm);
        }
 #endif
-       if (rc == -1) {         /* no sparc, or RTCSET failed */
-               ioctlname = "RTC_SET_TIME";
-               rc = ioctl(rtc_fd, RTC_SET_TIME, new_broken_time);
-       }
 
        if (rc == -1) {
                warn(_("ioctl(%s) to %s to set the time failed."),