[PATCH 1/2] busybox: fix build with musl 1.2.0
Rosen Penev
rosenp at gmail.com
Sun Aug 30 21:10:07 EDT 2020
SYS_settimeofday is no longer present. That is, it's replaced with the
time32 variant. There is no time64 variant.
Note that 5a7c064bdbb71bfbcded073c7c0a8723be306009 switched the patch to
use the syscall instead of the function as musl's settimeofday does not
use the tz argument for anything.
Instead of fixing it, just remove the patch. date -k can be replaced
with hwclock --systz.
On that note, backported a glibc patch fixing a settimeofday issue on
versions 2.31 and above.
Added a second patch fixing settimeofday issues with hwclock and musl.
Removed useless busybox patches
The first two are useless as /bin/sh can execute those scripts just
fine. Shellcheck reports no problems.
Telnet patch is useless as telnet is no longer used in OpenWrt.
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
package/utils/busybox/Makefile | 2 +-
...rappers-around-clock_gettime-closes-.patch | 104 ++++++++++++++++++
.../patches/003-hwclock-settimeofday.patch | 55 +++++++++
...ck-use-settimeofday-syscall-directly.patch | 66 +++++++++++
.../busybox/patches/100-trylink_bash.patch | 8 --
.../patches/101-gen_build_files_bash.patch | 8 --
.../busybox/patches/240-telnetd_intr.patch | 10 --
.../busybox/patches/250-date-k-flag.patch | 92 ----------------
8 files changed, 226 insertions(+), 119 deletions(-)
create mode 100644 package/utils/busybox/patches/002-Remove-syscall-wrappers-around-clock_gettime-closes-.patch
create mode 100644 package/utils/busybox/patches/003-hwclock-settimeofday.patch
create mode 100644 package/utils/busybox/patches/004-hwclock-use-settimeofday-syscall-directly.patch
delete mode 100644 package/utils/busybox/patches/100-trylink_bash.patch
delete mode 100644 package/utils/busybox/patches/101-gen_build_files_bash.patch
delete mode 100644 package/utils/busybox/patches/240-telnetd_intr.patch
delete mode 100644 package/utils/busybox/patches/250-date-k-flag.patch
diff --git a/package/utils/busybox/Makefile b/package/utils/busybox/Makefile
index 0b56e0b9fd..1fd66b79a4 100644
--- a/package/utils/busybox/Makefile
+++ b/package/utils/busybox/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=busybox
PKG_VERSION:=1.31.1
-PKG_RELEASE:=3
+PKG_RELEASE:=4
PKG_FLAGS:=essential
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
diff --git a/package/utils/busybox/patches/002-Remove-syscall-wrappers-around-clock_gettime-closes-.patch b/package/utils/busybox/patches/002-Remove-syscall-wrappers-around-clock_gettime-closes-.patch
new file mode 100644
index 0000000000..27a4f2ea38
--- /dev/null
+++ b/package/utils/busybox/patches/002-Remove-syscall-wrappers-around-clock_gettime-closes-.patch
@@ -0,0 +1,104 @@
+From be5a505d771a77c640acc35ceaa470c80e62f954 Mon Sep 17 00:00:00 2001
+From: Denys Vlasenko <vda.linux at googlemail.com>
+Date: Thu, 24 Oct 2019 16:26:55 +0200
+Subject: [PATCH] Remove syscall wrappers around clock_gettime, closes 12091
+
+12091 "Direct use of __NR_clock_gettime is not time64-safe".
+
+function old new delta
+runsv_main 1698 1712 +14
+startservice 378 383 +5
+get_mono 31 25 -6
+date_main 932 926 -6
+gettimeofday_ns 17 - -17
+------------------------------------------------------------------------------
+(add/remove: 0/1 grow/shrink: 2/2 up/down: 19/-29) Total: -10 bytes
+
+Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
+---
+ Makefile.flags | 6 ++++--
+ coreutils/date.c | 16 +++-------------
+ libbb/time.c | 11 +----------
+ runit/runsv.c | 11 +----------
+ 4 files changed, 9 insertions(+), 35 deletions(-)
+
+diff --git a/Makefile.flags b/Makefile.flags
+index 6f6142cc5..bea464753 100644
+--- a/Makefile.flags
++++ b/Makefile.flags
+@@ -129,10 +129,12 @@ endif
+ # fall back to using a temp file:
+ CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >crypttest.c; $(CC) $(CFLAGS) -lcrypt -o /dev/null crypttest.c >/dev/null 2>&1 && echo "y"; rm crypttest.c)
+ ifeq ($(CRYPT_AVAILABLE),y)
+-LDLIBS += m crypt
++LDLIBS += m rt crypt
+ else
+-LDLIBS += m
++LDLIBS += m rt
+ endif
++# libm may be needed for dc, awk, ntpd
++# librt may be needed for clock_gettime()
+
+ # libpam may use libpthread, libdl and/or libaudit.
+ # On some platforms that requires an explicit -lpthread, -ldl, -laudit.
+diff --git a/coreutils/date.c b/coreutils/date.c
+index 731241536..f7e9a8d0e 100644
+--- a/coreutils/date.c
++++ b/coreutils/date.c
+@@ -33,10 +33,9 @@
+ //config: Enable option (-I) to output an ISO-8601 compliant
+ //config: date/time string.
+ //config:
+-//config:# defaults to "no": stat's nanosecond field is a bit non-portable
+ //config:config FEATURE_DATE_NANO
+ //config: bool "Support %[num]N nanosecond format specifier"
+-//config: default n # syscall(__NR_clock_gettime)
++//config: default n # stat's nanosecond field is a bit non-portable
+ //config: depends on DATE
+ //config: select PLATFORM_LINUX
+ //config: help
+@@ -272,9 +271,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
+ #endif
+ } else {
+ #if ENABLE_FEATURE_DATE_NANO
+- /* libc has incredibly messy way of doing this,
+- * typically requiring -lrt. We just skip all this mess */
+- syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
++ clock_gettime(CLOCK_REALTIME, &ts);
+ #else
+ time(&ts.tv_sec);
+ #endif
+diff --git a/libbb/time.c b/libbb/time.c
+index b6fcae28b..e66a9cba8 100644
+--- a/libbb/time.c
++++ b/libbb/time.c
+@@ -253,11 +253,9 @@ char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp)
+ #define CLOCK_MONOTONIC 1
+ #endif
+
+-/* libc has incredibly messy way of doing this,
+- * typically requiring -lrt. We just skip all this mess */
+ static void get_mono(struct timespec *ts)
+ {
+- if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts))
++ if (clock_gettime(CLOCK_MONOTONIC, ts))
+ bb_error_msg_and_die("clock_gettime(MONOTONIC) failed");
+ }
+ unsigned long long FAST_FUNC monotonic_ns(void)
+diff --git a/runit/runsv.c b/runit/runsv.c
+index 737909b0e..36d85101e 100644
+--- a/runit/runsv.c
++++ b/runit/runsv.c
+@@ -51,11 +51,9 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ #if ENABLE_MONOTONIC_SYSCALL
+ #include <sys/syscall.h>
+
+-/* libc has incredibly messy way of doing this,
+- * typically requiring -lrt. We just skip all this mess */
+ static void gettimeofday_ns(struct timespec *ts)
+ {
+- syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
++ clock_gettime(CLOCK_REALTIME, ts);
+ }
+ #else
+ static void gettimeofday_ns(struct timespec *ts)
diff --git a/package/utils/busybox/patches/003-hwclock-settimeofday.patch b/package/utils/busybox/patches/003-hwclock-settimeofday.patch
new file mode 100644
index 0000000000..df1ae911bf
--- /dev/null
+++ b/package/utils/busybox/patches/003-hwclock-settimeofday.patch
@@ -0,0 +1,55 @@
+From 1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b Mon Sep 17 00:00:00 2001
+From: Eddie James <eajames at linux.ibm.com>
+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 <eajames at linux.ibm.com>
+Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
+---
+ 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
+@@ -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_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_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_perror_msg_and_die("settimeofday");
++ if (settimeofday(&tv, NULL))
+ bb_perror_msg_and_die("settimeofday");
+ }
+
diff --git a/package/utils/busybox/patches/004-hwclock-use-settimeofday-syscall-directly.patch b/package/utils/busybox/patches/004-hwclock-use-settimeofday-syscall-directly.patch
new file mode 100644
index 0000000000..d4d87ffcf7
--- /dev/null
+++ b/package/utils/busybox/patches/004-hwclock-use-settimeofday-syscall-directly.patch
@@ -0,0 +1,66 @@
+From 2be57f27e8a8ae447c45524a3735ee02727b0345 Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp at gmail.com>
+Date: Thu, 27 Aug 2020 18:19:04 -0700
+Subject: [PATCH] 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>
+---
+ 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..0c4a5c9ec 100644
+--- a/util-linux/hwclock.c
++++ b/util-linux/hwclock.c
+@@ -34,6 +34,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"
+
+@@ -49,6 +50,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)
+@@ -129,8 +134,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_perror_msg_and_die("settimeofday");
+
+ tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
+@@ -288,8 +295,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_perror_msg_and_die("settimeofday");
+ if (settimeofday(&tv, NULL))
+ bb_perror_msg_and_die("settimeofday");
+
diff --git a/package/utils/busybox/patches/100-trylink_bash.patch b/package/utils/busybox/patches/100-trylink_bash.patch
deleted file mode 100644
index f9571fcbc8..0000000000
--- a/package/utils/busybox/patches/100-trylink_bash.patch
+++ /dev/null
@@ -1,8 +0,0 @@
---- a/scripts/trylink
-+++ b/scripts/trylink
-@@ -1,4 +1,4 @@
--#!/bin/sh
-+#!/usr/bin/env bash
-
- debug=false
-
diff --git a/package/utils/busybox/patches/101-gen_build_files_bash.patch b/package/utils/busybox/patches/101-gen_build_files_bash.patch
deleted file mode 100644
index d258fb8bc4..0000000000
--- a/package/utils/busybox/patches/101-gen_build_files_bash.patch
+++ /dev/null
@@ -1,8 +0,0 @@
---- a/scripts/gen_build_files.sh
-+++ b/scripts/gen_build_files.sh
-@@ -1,4 +1,4 @@
--#!/bin/sh
-+#!/usr/bin/env bash
-
- # Note: was using sed OPTS CMD -- FILES
- # but users complain that many sed implementations
diff --git a/package/utils/busybox/patches/240-telnetd_intr.patch b/package/utils/busybox/patches/240-telnetd_intr.patch
deleted file mode 100644
index 773ba44db5..0000000000
--- a/package/utils/busybox/patches/240-telnetd_intr.patch
+++ /dev/null
@@ -1,10 +0,0 @@
---- a/networking/telnetd.c
-+++ b/networking/telnetd.c
-@@ -509,6 +509,7 @@ make_new_session(
-
- /* Restore default signal handling ASAP */
- bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL);
-+ signal(SIGINT, SIG_DFL);
-
- pid = getpid();
-
diff --git a/package/utils/busybox/patches/250-date-k-flag.patch b/package/utils/busybox/patches/250-date-k-flag.patch
deleted file mode 100644
index 5aadbb233c..0000000000
--- a/package/utils/busybox/patches/250-date-k-flag.patch
+++ /dev/null
@@ -1,92 +0,0 @@
---- a/coreutils/date.c
-+++ b/coreutils/date.c
-@@ -123,6 +123,7 @@
- //usage: IF_FEATURE_DATE_ISOFMT(
- //usage: "\n -D FMT Use FMT (strptime format) for -d TIME conversion"
- //usage: )
-+//usage: "\n -k Set Kernel timezone from localtime and exit"
- //usage: "\n"
- //usage: "\nRecognized TIME formats:"
- //usage: "\n hh:mm[:ss]"
-@@ -139,9 +140,8 @@
-
- #include "libbb.h"
- #include "common_bufsiz.h"
--#if ENABLE_FEATURE_DATE_NANO
--# include <sys/syscall.h>
--#endif
-+#include <sys/time.h>
-+#include <sys/syscall.h>
-
- enum {
- OPT_RFC2822 = (1 << 0), /* R */
-@@ -149,8 +149,9 @@ enum {
- OPT_UTC = (1 << 2), /* u */
- OPT_DATE = (1 << 3), /* d */
- OPT_REFERENCE = (1 << 4), /* r */
-- OPT_TIMESPEC = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
-- OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
-+ OPT_KERNELTZ = (1 << 5), /* k */
-+ OPT_TIMESPEC = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
-+ OPT_HINT = (1 << 7) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
- };
-
- #if ENABLE_LONG_OPTS
-@@ -162,6 +163,7 @@ static const char date_longopts[] ALIGN1
- /* "universal\0" No_argument "u" */
- "date\0" Required_argument "d"
- "reference\0" Required_argument "r"
-+ "set-kernel-tz\0" No_argument "k"
- ;
- #endif
-
-@@ -181,6 +183,8 @@ static void maybe_set_utc(int opt)
- int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
- int date_main(int argc UNUSED_PARAM, char **argv)
- {
-+ time_t tt;
-+ struct timezone tz;
- struct timespec ts;
- struct tm tm_time;
- char buf_fmt_dt2str[64];
-@@ -193,7 +197,7 @@ int date_main(int argc UNUSED_PARAM, cha
- char *isofmt_arg = NULL;
-
- opt = getopt32long(argv, "^"
-- "Rs:ud:r:"
-+ "Rs:ud:r:k"
- IF_FEATURE_DATE_ISOFMT("I::D:")
- "\0"
- "d--s:s--d"
-@@ -256,6 +260,31 @@ int date_main(int argc UNUSED_PARAM, cha
- if (*argv)
- bb_show_usage();
-
-+ /* Setting of kernel timezone was requested */
-+ if (opt & OPT_KERNELTZ) {
-+ tt = time(NULL);
-+ localtime_r(&tt, &tm_time);
-+
-+ /* workaround warp_clock() on first invocation */
-+ memset(&tz, 0, sizeof(tz));
-+ syscall(SYS_settimeofday, NULL, &tz);
-+
-+ memset(&tz, 0, sizeof(tz));
-+#ifdef __USE_MISC
-+ tz.tz_minuteswest = -(tm_time.tm_gmtoff / 60);
-+#else
-+ tz.tz_minuteswest = -(tm_time.__tm_gmtoff / 60);
-+#endif
-+
-+ if (syscall(SYS_settimeofday, NULL, &tz))
-+ {
-+ bb_perror_msg("can't set kernel time zone");
-+ return EXIT_FAILURE;
-+ }
-+
-+ return EXIT_SUCCESS;
-+ }
-+
- /* Now we have parsed all the information except the date format
- * which depends on whether the clock is being set or read */
-
--
2.26.2
More information about the openwrt-devel
mailing list