diff options
author | Eddie James <eajames@linux.ibm.com> | 2020-08-10 09:59:02 -0500 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-08-15 22:29:00 +0200 |
commit | 1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b (patch) | |
tree | ce68e4c6412be03ebe27f71ea6b55b9f2de5b2ed | |
parent | a77f3ecf68c63081934f5e0800eab80b5098bb24 (diff) | |
download | busybox-w32-1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b.tar.gz busybox-w32-1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b.tar.bz2 busybox-w32-1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b.zip |
hwclock: Fix settimeofday for glibc v2.31+
The glibc implementation changed for settimeofday, resulting in "invalid
argument" error when attempting to set both timezone and time with a single
call. Fix this by calling settimeofday twice
Signed-off-by: Eddie James <eajames@linux.ibm.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/hwclock.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 357906cca..e85bca2b2 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -121,16 +121,20 @@ static void to_sys_clock(const char **pp_rtcname, int utc) | |||
121 | struct timeval tv; | 121 | struct timeval tv; |
122 | struct timezone tz; | 122 | struct timezone tz; |
123 | 123 | ||
124 | tz.tz_minuteswest = timezone/60; | 124 | tz.tz_minuteswest = timezone / 60; |
125 | /* ^^^ used to also subtract 60*daylight, but it's wrong: | 125 | /* ^^^ used to also subtract 60*daylight, but it's wrong: |
126 | * daylight!=0 means "this timezone has some DST | 126 | * daylight!=0 means "this timezone has some DST |
127 | * during the year", not "DST is in effect now". | 127 | * during the year", not "DST is in effect now". |
128 | */ | 128 | */ |
129 | tz.tz_dsttime = 0; | 129 | tz.tz_dsttime = 0; |
130 | 130 | ||
131 | /* glibc v2.31+ returns an error if both args are non-NULL */ | ||
132 | if (settimeofday(NULL, &tz)) | ||
133 | bb_simple_perror_msg_and_die("settimeofday"); | ||
134 | |||
131 | tv.tv_sec = read_rtc(pp_rtcname, NULL, utc); | 135 | tv.tv_sec = read_rtc(pp_rtcname, NULL, utc); |
132 | tv.tv_usec = 0; | 136 | tv.tv_usec = 0; |
133 | if (settimeofday(&tv, &tz)) | 137 | if (settimeofday(&tv, NULL)) |
134 | bb_simple_perror_msg_and_die("settimeofday"); | 138 | bb_simple_perror_msg_and_die("settimeofday"); |
135 | } | 139 | } |
136 | 140 | ||
@@ -282,7 +286,11 @@ static void set_system_clock_timezone(int utc) | |||
282 | gettimeofday(&tv, NULL); | 286 | gettimeofday(&tv, NULL); |
283 | if (!utc) | 287 | if (!utc) |
284 | tv.tv_sec += tz.tz_minuteswest * 60; | 288 | tv.tv_sec += tz.tz_minuteswest * 60; |
285 | if (settimeofday(&tv, &tz)) | 289 | |
290 | /* glibc v2.31+ returns an error if both args are non-NULL */ | ||
291 | if (settimeofday(NULL, &tz)) | ||
292 | bb_simple_perror_msg_and_die("settimeofday"); | ||
293 | if (settimeofday(&tv, NULL)) | ||
286 | bb_simple_perror_msg_and_die("settimeofday"); | 294 | bb_simple_perror_msg_and_die("settimeofday"); |
287 | } | 295 | } |
288 | 296 | ||