AW: [PATCHv2] hwclock: use settimeofday syscall directly
Walter Harms
wharms at bfs.de
Mon Aug 31 16:22:33 UTC 2020
maybe its a bit late but ...
doing syscall() is always last resort, IMHO it would
be better to separate this into a bb_set_tod() and
put all the strings here ... and replace it when the
libc guys have a single standard.
jm2c,
re,
wh
________________________________________
Von: busybox [busybox-bounces at busybox.net] im Auftrag von Rosen Penev [rosenp at gmail.com]
Gesendet: Montag, 31. August 2020 03:51
An: busybox at busybox.net
Betreff: [PATCHv2] hwclock: use settimeofday syscall directly
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 at gmail.com>
---
v2: don't use __NR. It's not correct to do so.
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..cf7c58507 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 */
+#ifndef SYS_settimeofday
+#define SYS_settimeofday SYS_settimeofday_time32
+#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 at busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list