[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] hwclock: use settimeofday syscall directly
From:       Rosen Penev <rosenp () gmail ! com>
Date:       2020-08-28 21:38:05
Message-ID: 20200828213805.23656-1-rosenp () gmail ! com
[Download RAW message or body]

musl's settimeofday implementation completely ignores the tz parameter.
While this is perfectly valid, it causes problems when wanting to set
the kernel timezone.

Added comments.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 util-linux/hwclock.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index e85bca2b2..700dd5628 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -33,6 +33,7 @@
 
 #include "libbb.h"
 /* After libbb.h, since it needs sys/types.h on some systems */
+#include <sys/syscall.h>
 #include <sys/utsname.h>
 #include "rtc_.h"
 
@@ -48,6 +49,10 @@
  */
 #define SHOW_HWCLOCK_DIFF 0
 
+/* musl 1.2.0+ does not have SYS_settimeofday */
+#if !defined(SYS_settimeofday) && defined(__NR_settimeofday)
+#define SYS_settimeofday __NR_settimeofday
+#endif
 
 #if !SHOW_HWCLOCK_DIFF
 # define read_rtc(pp_rtcname, sys_tv, utc) read_rtc(pp_rtcname, utc)
@@ -128,8 +133,10 @@ static void to_sys_clock(const char **pp_rtcname, int utc)
 	 */
 	tz.tz_dsttime = 0;
 
-	/* glibc v2.31+ returns an error if both args are non-NULL */
-	if (settimeofday(NULL, &tz))
+	/* glibc v2.31+ returns an error if both args are non-NULL
+	 * musl completely ignores the tz parameter
+	 */
+	if (syscall(SYS_settimeofday, NULL, &tz))
 		bb_simple_perror_msg_and_die("settimeofday");
 
 	tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
@@ -287,8 +294,10 @@ static void set_system_clock_timezone(int utc)
 	if (!utc)
 		tv.tv_sec += tz.tz_minuteswest * 60;
 
-	/* glibc v2.31+ returns an error if both args are non-NULL */
-	if (settimeofday(NULL, &tz))
+	/* glibc v2.31+ returns an error if both args are non-NULL
+	 * musl completely ignores the tz parameter
+	 */
+	if (syscall(SYS_settimeofday, NULL, &tz))
 		bb_simple_perror_msg_and_die("settimeofday");
 	if (settimeofday(&tv, NULL))
 		bb_simple_perror_msg_and_die("settimeofday");
-- 
2.26.2

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic