Skip to contentSkip to conversation

package/busybox: Fix hwclock for glibc 2.31+

PATCH Superseded Klaus Heinrich Kiwi 2 participants 7 messages Nov 12, 2020 – Nov 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/busybox: Fix hwclock for glibc 2.31+

Pick the below patch from upstream, in order to fix 'settimeofday: Invalid argument' introduced by using glibc v2.31+. (busybox hasn't tagged a new version since).

See https://bugs.busybox.net/show_bug.cgi?id=12756 for more info.

---
commit 1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b
Author: Eddie James <[email protected]>

hwclock: Fix settimeofday for glibc v2.31+
---

---
 ...ock-Fix-settimeofday-for-glibc-v2.31.patch | 58 +++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch
package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch new file +58 -0
new file mode 100644
index 0000000000..98a0b01430
@@ -0,0 +1,58 @@
+From a4faa9af79c2a0f2b501c0fd507842e4966fc23b Mon Sep 17 00:00:00 2001
+From: Eddie James <[email protected]>
+Date: Mon, 10 Aug 2020 09:59:02 -0500
+Subject: [PATCH] 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 <[email protected]>
+Signed-off-by: Denys Vlasenko <[email protected]>
+---
+ util-linux/hwclock.c | 14 +++++++++++---
+ 1 file changed, 11 insertions(+), 3 deletions(-)
+
+diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
+index dc97d8fb4..2479e7416 100644
+--- a/util-linux/hwclock.c
++++ b/util-linux/hwclock.c
+@@ -122,16 +122,20 @@ static void to_sys_clock(const char **pp_rtcname, int utc)
+ 	struct timeval tv;
+ 	struct timezone tz;
+ 
+-	tz.tz_minuteswest = timezone/60;
++	tz.tz_minuteswest = timezone / 60;
+ 	/* ^^^ used to also subtract 60*daylight, but it's wrong:
+ 	 * daylight!=0 means "this timezone has some DST
+ 	 * during the year", not "DST is in effect now".
+ 	 */
+ 	tz.tz_dsttime = 0;
+ 
++	/* glibc v2.31+ returns an error if both args are non-NULL */
++	if (settimeofday(NULL, &tz))
++		bb_simple_perror_msg_and_die("settimeofday");
++
+ 	tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
+ 	tv.tv_usec = 0;
+-	if (settimeofday(&tv, &tz))
++	if (settimeofday(&tv, NULL))
+ 		bb_simple_perror_msg_and_die("settimeofday");
+ }
+ 
+@@ -283,7 +287,11 @@ static void set_system_clock_timezone(int utc)
+ 	gettimeofday(&tv, NULL);
+ 	if (!utc)
+ 		tv.tv_sec += tz.tz_minuteswest * 60;
+-	if (settimeofday(&tv, &tz))
++
++	/* glibc v2.31+ returns an error if both args are non-NULL */
++	if (settimeofday(NULL, &tz))
++		bb_simple_perror_msg_and_die("settimeofday");
++	if (settimeofday(&tv, NULL))
+ 		bb_simple_perror_msg_and_die("settimeofday");
+ }
+ 
+-- 
+2.17.1
+
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 package/busybox: Fix hwclock for glibc 2.31+

Quoted 16 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Klaus" == Klaus Heinrich Kiwi <[email protected]> writes:

Pick the below patch from upstream, in order to fix 'settimeofday: Invalid argument' introduced by using glibc v2.31+. (busybox hasn't tagged a new version since).

See https://bugs.busybox.net/show_bug.cgi?id=12756 for more info.

---
commit 1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b
Author: Eddie James <[email protected]>

hwclock: Fix settimeofday for glibc v2.31+
---
+++ b/package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch

package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch line 1

Quoted 1 line
package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch new file +1 -0
@@ -0,0 +1,58 @@
+From a4faa9af79c2a0f2b501c0fd507842e4966fc23b Mon Sep 17 00:00:00 2001

How did you end up with a different git hash here?

Committed after fixing that, thanks.

Signature · 1 line
Bye, Peter Korsgaard
#2 lore raw

PATCH 1/1 package/busybox: Fix hwclock for glibc 2.31+

Quoted 7 lines · Peter Korsgaard

package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch line 1

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Klaus" == Klaus Heinrich Kiwi <[email protected]> writes:

---
+++ b/package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch

package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch new file +1 -0
@@ -0,0 +1,58 @@
+From a4faa9af79c2a0f2b501c0fd507842e4966fc23b Mon Sep 17 00:00:00 2001

How did you end up with a different git hash here?

I took busybox tag 1_32_0, applied the patches found on buildroot/package/busybox, then cherry-picked the above patch and git format-patch HEAD^

Guess I was being too cautious by applying the patches locally first?

At any rate, I'm sending a second version where I format-patch'ed the patch itself (i.e., from busybox master), instead of applying it on top of a local 1_32_0 tree along with other buildroot build-time patches.

Quoted 3 lines

Committed after fixing that, thanks.

Thanks,

-Klaus

Signature · 1 line
Klaus Heinrich Kiwi <[email protected]>
#3 lore raw

PATCH 1/1 package/busybox: Fix hwclock for glibc 2.31+

Quoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Klaus" == Klaus Heinrich Kiwi <[email protected]> writes:

Quoted 7 lines · Peter Korsgaard

package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch line 1

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Klaus" == Klaus Heinrich Kiwi <[email protected]> writes:

---
+++ b/package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch

package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch new file +1 -0
@@ -0,0 +1,58 @@
+From a4faa9af79c2a0f2b501c0fd507842e4966fc23b Mon Sep 17 00:00:00 2001

How did you end up with a different git hash here?

Quoted 4 lines

I took busybox tag 1_32_0, applied the patches found on buildroot/package/busybox, then cherry-picked the above patch and git format-patch HEAD^

Guess I was being too cautious by applying the patches locally first?

That is also fine, but then use the -x option to git cherry-pick so the original git hash is tracked.

Quoted 3 lines

At any rate, I'm sending a second version where I format-patch'ed the patch itself (i.e., from busybox master), instead of applying it on top of a local 1_32_0 tree along with other buildroot build-time patches.

That is not needed as I already applied this patch.

Thanks!

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH 1/1 package/busybox: Fix hwclock for glibc 2.31+

Quoted 3 lines · Peter Korsgaard

That is also fine, but then use the -x option to git cherry-pick so the original git hash is tracked.

Odd, I kinda always automatically cherry-pick with -xs, not sure how I missed that this time.

Quoted 9 lines
Quoted 4 lines

At any rate, I'm sending a second version where I format-patch'ed the patch itself (i.e., from busybox master), instead of applying it on top of a local 1_32_0 tree along with other buildroot build-time patches.

That is not needed as I already applied this patch.

Thanks!

Thanks!

I'll send a similar patch to buildroot 2020.08.1 (hopefully this is still active?) and 2020.02.7 (in case it's really affected - need to double check) - but those will require a small change to apply on top of busybox 1_31_1..

-Klaus

Signature · 1 line
Klaus Heinrich Kiwi <[email protected]>
#5 lore raw

PATCH 1/1 package/busybox: Fix hwclock for glibc 2.31+

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Klaus" == Klaus Heinrich Kiwi <[email protected]> writes:

Hi,

Quoted 6 lines

Thanks!

I'll send a similar patch to buildroot 2020.08.1 (hopefully this is still active?) and 2020.02.7 (in case it's really affected - need to double check) - but those will require a small change to apply on top of busybox 1_31_1..

Yes, 2020.02.x (until April 2021) and 2020.08.x (until January 2021) are still supported. 2020.02.x uses glibc 2.30 though, so it isn't needed there.

Signature · 1 line
Bye, Peter Korsgaard
#6 lore raw

PATCH v2 1/1 package/busybox: Fix hwclock for glibc 2.31+

In reply to Peter Korsgaard

Pick the below patch from upstream, in order to fix 'settimeofday: Invalid argument' introduced by using glibc v2.31+. (busybox hasn't tagged a new version since).

See https://bugs.busybox.net/show_bug.cgi?id=12756 for more info.

commit 1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b
Author: Eddie James <[email protected]>

hwclock: Fix settimeofday for glibc v2.31+

---
Changes v1 -> V2:
- format-patch from the commit itself, instead of applying staged patches on top of 1_32_0

---
 ...ock-Fix-settimeofday-for-glibc-v2.31.patch | 58 +++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch
package/busybox/0003-hwclock-Fix-settimeofday-for-glibc-v2.31.patch new file +58 -0
new file mode 100644
index 0000000000..486d3dead3
@@ -0,0 +1,58 @@
+From 1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b Mon Sep 17 00:00:00 2001
+From: Eddie James <[email protected]>
+Date: Mon, 10 Aug 2020 09:59:02 -0500
+Subject: [PATCH] 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 <[email protected]>
+Signed-off-by: Denys Vlasenko <[email protected]>
+---
+ util-linux/hwclock.c | 14 +++++++++++---
+ 1 file 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)
+ 	struct timeval tv;
+ 	struct timezone tz;
+ 
+-	tz.tz_minuteswest = timezone/60;
++	tz.tz_minuteswest = timezone / 60;
+ 	/* ^^^ used to also subtract 60*daylight, but it's wrong:
+ 	 * daylight!=0 means "this timezone has some DST
+ 	 * during the year", not "DST is in effect now".
+ 	 */
+ 	tz.tz_dsttime = 0;
+ 
++	/* glibc v2.31+ returns an error if both args are non-NULL */
++	if (settimeofday(NULL, &tz))
++		bb_simple_perror_msg_and_die("settimeofday");
++
+ 	tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
+ 	tv.tv_usec = 0;
+-	if (settimeofday(&tv, &tz))
++	if (settimeofday(&tv, NULL))
+ 		bb_simple_perror_msg_and_die("settimeofday");
+ }
+ 
+@@ -282,7 +286,11 @@ static void set_system_clock_timezone(int utc)
+ 	gettimeofday(&tv, NULL);
+ 	if (!utc)
+ 		tv.tv_sec += tz.tz_minuteswest * 60;
+-	if (settimeofday(&tv, &tz))
++
++	/* glibc v2.31+ returns an error if both args are non-NULL */
++	if (settimeofday(NULL, &tz))
++		bb_simple_perror_msg_and_die("settimeofday");
++	if (settimeofday(&tv, NULL))
+ 		bb_simple_perror_msg_and_die("settimeofday");
+ }
+ 
+-- 
+2.17.1
+
Signature · 1 line
2.17.1