[PATCH] hwclock: separate invocations settimeofday time&zone

Lukasz Serafin Lukasz.Serafin at axis.com
Tue Jul 14 12:08:59 UTC 2020


Refactor usage of settimeofday to be compatible with glibc v2.31.

Signed-off-by: Fredrik M Olsson <fredriol at axis.com>
---
 util-linux/hwclock.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index 29f5102..d3884f6 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -117,6 +117,20 @@ static void show_clock(const char **pp_rtcname, int utc)
 #endif
 }

+static void set_time_and_zone(const struct timeval *tv, const struct timezone *tz)
+{
+#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 31
+    if (settimeofday(NULL, tz))
+        bb_perror_msg_and_die("settimeofday tz");
+
+    if (settimeofday(tv, NULL))
+        bb_perror_msg_and_die("settimeofday tv");
+#else
+    if (settimeofday(tv, tz))
+        bb_perror_msg_and_die("settimeofday");
+#endif
+}
+
 static void to_sys_clock(const char **pp_rtcname, int utc)
 {
     struct timeval tv;
@@ -131,8 +145,7 @@ static void to_sys_clock(const char **pp_rtcname, int utc)

     tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
     tv.tv_usec = 0;
-    if (settimeofday(&tv, &tz))
-        bb_perror_msg_and_die("settimeofday");
+    set_time_and_zone(&tv, &tz);
 }

 static void from_sys_clock(const char **pp_rtcname, int utc)
@@ -283,8 +296,7 @@ static void set_system_clock_timezone(int utc)
     gettimeofday(&tv, NULL);
     if (!utc)
         tv.tv_sec += tz.tz_minuteswest * 60;
-    if (settimeofday(&tv, &tz))
-        bb_perror_msg_and_die("settimeofday");
+    set_time_and_zone(&tv, &tz);
 }

 //usage:#define hwclock_trivial_usage
--
2.11.0

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20200714/f745bc49/attachment.html>


More information about the busybox mailing list