diff options
author | Sami Kerola | 2016-07-26 11:52:15 +0200 |
---|---|---|
committer | Sami Kerola | 2017-02-05 00:39:38 +0100 |
commit | fc35f2db798eb101d5a114304bae6131d6b50726 (patch) | |
tree | aacfdd67d8f332a45bf0379ccc0171ad5da427e5 /sys-utils/hwclock-rtc.c | |
parent | hwclock: stream line synchronize_to_clock_tick_rtc() (diff) | |
download | kernel-qcow2-util-linux-fc35f2db798eb101d5a114304bae6131d6b50726.tar.gz kernel-qcow2-util-linux-fc35f2db798eb101d5a114304bae6131d6b50726.tar.xz kernel-qcow2-util-linux-fc35f2db798eb101d5a114304bae6131d6b50726.zip |
hwclock: try RTCGET and RTCSET only when normal rtc fails
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>
Diffstat (limited to 'sys-utils/hwclock-rtc.c')
-rw-r--r-- | sys-utils/hwclock-rtc.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/sys-utils/hwclock-rtc.c b/sys-utils/hwclock-rtc.c index ba1882313..fa5e07b11 100644 --- a/sys-utils/hwclock-rtc.c +++ b/sys-utils/hwclock-rtc.c @@ -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."), |