diff --git a/busybox.config b/busybox.config index 4b2642a..32a916f 100644 --- a/busybox.config +++ b/busybox.config @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.36.1 -# Tue May 23 17:20:45 2023 +# Mon Jul 15 18:16:39 2024 # CONFIG_HAVE_DOT_CONFIG=y @@ -94,8 +94,8 @@ CONFIG_FEATURE_BUFFERS_USE_MALLOC=y CONFIG_PASSWORD_MINLEN=6 CONFIG_MD5_SMALL=1 CONFIG_SHA1_SMALL=3 -CONFIG_SHA1_HWACCEL=1 -CONFIG_SHA256_HWACCEL=1 +# CONFIG_SHA1_HWACCEL is not set +# CONFIG_SHA256_HWACCEL is not set CONFIG_SHA3_SMALL=1 # CONFIG_FEATURE_NON_POSIX_CP is not set CONFIG_FEATURE_VERBOSE_CP_MESSAGE=y @@ -298,7 +298,7 @@ CONFIG_MV=y CONFIG_NICE=y CONFIG_NL=y CONFIG_NOHUP=y -# CONFIG_NPROC is not set +CONFIG_NPROC=y CONFIG_OD=y CONFIG_PASTE=y CONFIG_PRINTENV=y @@ -325,7 +325,7 @@ CONFIG_FEATURE_STAT_FILESYSTEM=y CONFIG_STTY=y CONFIG_SUM=y CONFIG_SYNC=y -# CONFIG_FEATURE_SYNC_FANCY is not set +CONFIG_FEATURE_SYNC_FANCY=y CONFIG_FSYNC=y CONFIG_TAC=y CONFIG_TAIL=y @@ -481,7 +481,7 @@ CONFIG_FEATURE_FIND_DELETE=y CONFIG_FEATURE_FIND_EMPTY=y CONFIG_FEATURE_FIND_PATH=y CONFIG_FEATURE_FIND_REGEX=y -# CONFIG_FEATURE_FIND_CONTEXT is not set +CONFIG_FEATURE_FIND_CONTEXT=y CONFIG_FEATURE_FIND_LINKS=y CONFIG_GREP=y CONFIG_EGREP=y @@ -503,9 +503,9 @@ CONFIG_FEATURE_XARGS_SUPPORT_ARGS_FILE=y # CONFIG_FEATURE_BOOTCHARTD_BLOATED_HEADER is not set # CONFIG_FEATURE_BOOTCHARTD_CONFIG_FILE is not set # CONFIG_HALT is not set -CONFIG_POWEROFF=y -CONFIG_REBOOT=y -CONFIG_FEATURE_WAIT_FOR_INIT=y +# CONFIG_POWEROFF is not set +# CONFIG_REBOOT is not set +# CONFIG_FEATURE_WAIT_FOR_INIT is not set # CONFIG_FEATURE_CALL_TELINIT is not set CONFIG_TELINIT_PATH="" # CONFIG_INIT is not set @@ -613,7 +613,7 @@ CONFIG_DMESG=y CONFIG_FEATURE_DMESG_PRETTY=y CONFIG_EJECT=y CONFIG_FEATURE_EJECT_SCSI=y -# CONFIG_FALLOCATE is not set +CONFIG_FALLOCATE=y CONFIG_FATATTR=y CONFIG_FBSET=y CONFIG_FEATURE_FBSET_FANCY=y @@ -661,11 +661,11 @@ CONFIG_MESG=y CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y CONFIG_MKE2FS=y CONFIG_MKFS_EXT2=y -CONFIG_MKFS_MINIX=y -CONFIG_FEATURE_MINIX2=y -CONFIG_MKFS_REISER=y -CONFIG_MKDOSFS=y -CONFIG_MKFS_VFAT=y +# CONFIG_MKFS_MINIX is not set +# CONFIG_FEATURE_MINIX2 is not set +# CONFIG_MKFS_REISER is not set +# CONFIG_MKDOSFS is not set +# CONFIG_MKFS_VFAT is not set CONFIG_MKSWAP=y CONFIG_FEATURE_MKSWAP_UUID=y CONFIG_MORE=y @@ -968,8 +968,8 @@ CONFIG_PSCAN=y CONFIG_ROUTE=y CONFIG_SLATTACH=y CONFIG_SSL_CLIENT=y -# CONFIG_TC is not set -# CONFIG_FEATURE_TC_INGRESS is not set +CONFIG_TC=y +CONFIG_FEATURE_TC_INGRESS=y CONFIG_TCPSVD=y CONFIG_UDPSVD=y CONFIG_TELNET=y @@ -1208,7 +1208,7 @@ CONFIG_FEATURE_SH_EXTRA_QUIET=y # CONFIG_FEATURE_SH_STANDALONE is not set # CONFIG_FEATURE_SH_NOFORK is not set CONFIG_FEATURE_SH_READ_FRAC=y -CONFIG_FEATURE_SH_HISTFILESIZE=y +# CONFIG_FEATURE_SH_HISTFILESIZE is not set CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS=y # diff --git a/busybox.mk b/busybox.mk index dca3151..49d45c8 100644 --- a/busybox.mk +++ b/busybox.mk @@ -5,11 +5,9 @@ include $(CLEAR_VARS) LOCAL_MODULE := busybox LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_STATIC_LIBRARIES := libselinux -LOCAL_DISABLE_FORMAT_STRING_CHECKS := true LOCAL_LDFLAGS := -static -Wl,--wrap=realpath -Wl,--wrap=rename -Wl,--wrap=renameat LOCAL_CFLAGS := \ -w -include include/autoconf.h -D__USE_BSD -D__USE_GNU \ --DBB_VER=\"$(BB_VER)\" -DBB_BT=AUTOCONF_TIMESTAMP \ --Wno-implicit-function-declaration +-DBB_VER=\"$(BB_VER)\" -DBB_BT=AUTOCONF_TIMESTAMP LOCAL_SRC_FILES := \ diff --git a/patches/0001-Fix-incorrect-assumptions-about-NDK.patch b/patches/0001-Fix-incorrect-assumptions-about-NDK.patch new file mode 100644 index 0000000..c014913 --- /dev/null +++ b/patches/0001-Fix-incorrect-assumptions-about-NDK.patch @@ -0,0 +1,106 @@ +From 4d264bc921b1a74381d356167b4c15673c819456 Mon Sep 17 00:00:00 2001 +From: topjohnwu +Date: Sat, 13 Jul 2024 18:26:16 -0700 +Subject: [PATCH 01/17] Fix incorrect assumptions about NDK + +--- + include/platform.h | 5 ++++- + libbb/missing_syscalls.c | 22 ---------------------- + miscutils/adjtimex.c | 6 +----- + util-linux/swaponoff.c | 4 +--- + 4 files changed, 6 insertions(+), 31 deletions(-) + +diff --git a/include/platform.h b/include/platform.h +index ea0512f36..e5bb07799 100644 +--- a/include/platform.h ++++ b/include/platform.h +@@ -545,12 +545,15 @@ typedef unsigned smalluint; + # if __ANDROID_API__ >= 21 + # undef HAVE_WAIT3 + # endif ++# if __ANDROID_API__ < 24 ++# undef HAVE_STRCHRNUL ++# endif + # undef HAVE_MEMPCPY +-# undef HAVE_STRCHRNUL + # undef HAVE_STRVERSCMP + # undef HAVE_UNLOCKED_LINE_OPS + # undef HAVE_NET_ETHERNET_H + # undef HAVE_PRINTF_PERCENTM ++# undef HAVE_SETBIT + #endif + + /* +diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c +index dc40d9155..92b44b388 100644 +--- a/libbb/missing_syscalls.c ++++ b/libbb/missing_syscalls.c +@@ -8,33 +8,11 @@ + #include "libbb.h" + + #if defined(ANDROID) || defined(__ANDROID__) +-/*# include - for struct timex, but may collide with */ + # include +-pid_t getsid(pid_t pid) +-{ +- return syscall(__NR_getsid, pid); +-} +- +-int sethostname(const char *name, size_t len) +-{ +- return syscall(__NR_sethostname, name, len); +-} +- +-struct timex; +-int adjtimex(struct timex *buf) +-{ +- return syscall(__NR_adjtimex, buf); +-} + + int pivot_root(const char *new_root, const char *put_old) + { + return syscall(__NR_pivot_root, new_root, put_old); + } + +-# if __ANDROID_API__ < 21 +-int tcdrain(int fd) +-{ +- return ioctl(fd, TCSBRK, 1); +-} +-# endif + #endif +diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c +index 209d1d560..06ee8e903 100644 +--- a/miscutils/adjtimex.c ++++ b/miscutils/adjtimex.c +@@ -33,11 +33,7 @@ + //usage: "\n -p TCONST" + + #include "libbb.h" +-#ifdef __BIONIC__ +-# include +-#else +-# include +-#endif ++#include + + static const uint16_t statlist_bit[] ALIGN2 = { + STA_PLL, +diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c +index e2ff4b5cc..67c384db6 100644 +--- a/util-linux/swaponoff.c ++++ b/util-linux/swaponoff.c +@@ -75,9 +75,7 @@ + #include "libbb.h" + #include "common_bufsiz.h" + #include +-#ifndef __BIONIC__ +-# include +-#endif ++#include + + #if ENABLE_FEATURE_SWAPONOFF_LABEL + # include "volume_id.h" +-- +2.45.2 + diff --git a/patches/0001-Fix-mconf-lkc-host-warning-statement-with-no-effect.patch b/patches/0001-Fix-mconf-lkc-host-warning-statement-with-no-effect.patch deleted file mode 100644 index d9d29ad..0000000 --- a/patches/0001-Fix-mconf-lkc-host-warning-statement-with-no-effect.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 534ef9f1b0676c20c9a821127e6cdf8107fb6cc7 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Fri, 27 Nov 2015 11:40:52 -0400 -Subject: [PATCH 01/35] Fix mconf/lkc host "warning statement with no effect" - ---- - scripts/kconfig/lkc.h | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h -index 527f60c99..1972cb9a0 100644 ---- a/scripts/kconfig/lkc.h -+++ b/scripts/kconfig/lkc.h -@@ -12,8 +12,8 @@ - # include - #else - # define gettext(Msgid) ((const char *) (Msgid)) --# define textdomain(Domainname) ((const char *) (Domainname)) --# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) -+# define textdomain(Domainname) -+# define bindtextdomain(Domainname, Dirname) - #endif - - #ifdef __cplusplus --- -2.45.2 - diff --git a/patches/0007-loadfont-setfont-conspy-add-missing-header.patch b/patches/0002-loadfont-setfont-conspy-add-missing-header.patch similarity index 92% rename from patches/0007-loadfont-setfont-conspy-add-missing-header.patch rename to patches/0002-loadfont-setfont-conspy-add-missing-header.patch index a0c4edf..07c7c4c 100644 --- a/patches/0007-loadfont-setfont-conspy-add-missing-header.patch +++ b/patches/0002-loadfont-setfont-conspy-add-missing-header.patch @@ -1,7 +1,7 @@ -From 048f41aea9fbaa920166369e4cf89fe1cc31693e Mon Sep 17 00:00:00 2001 +From 62dc3c2191e35983b619fc750f9f731c4a84a232 Mon Sep 17 00:00:00 2001 From: Chris Renshaw Date: Thu, 3 Dec 2015 01:29:35 -0400 -Subject: [PATCH 07/35] loadfont/setfont/conspy: add missing header +Subject: [PATCH 02/17] loadfont/setfont/conspy: add missing header Imported from dorimanx's combined ported header toolchain: https://github.com/dorimanx/android-busybox-ndk diff --git a/patches/0003-android-fix-mount-umount-fsck-df.patch b/patches/0003-android-fix-mount-umount-fsck-df.patch deleted file mode 100644 index 63a1fc1..0000000 --- a/patches/0003-android-fix-mount-umount-fsck-df.patch +++ /dev/null @@ -1,325 +0,0 @@ -From 00804b71ea96cdba92b33727e9c1b19ef14ff0bd Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Tue, 4 May 2021 00:56:55 -0300 -Subject: [PATCH 03/35] android: fix 'mount', 'umount', 'fsck', 'df' - -Patch by Tias Guns , based on 'Bionic Patch V1.0' by Vitaly Greck -https://code.google.com/p/busybox-android/downloads/detail?name=patch -Rebased for busybox 1.33.1 by Chris Renshaw ---- - libbb/Kbuild.src | 3 + - libbb/mntent_r.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 291 insertions(+) - create mode 100644 libbb/mntent_r.c - -diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src -index 653025e56..33c33b6be 100644 ---- a/libbb/Kbuild.src -+++ b/libbb/Kbuild.src -@@ -118,6 +118,9 @@ lib-y += xgethostbyname.o - lib-y += xreadlink.o - lib-y += xrealloc_vector.o - -+# for android-busybox-ndk -+lib-y += mntent_r.o -+ - lib-$(CONFIG_MOUNT) += match_fstype.o - lib-$(CONFIG_UMOUNT) += match_fstype.o - -diff --git a/libbb/mntent_r.c b/libbb/mntent_r.c -new file mode 100644 -index 000000000..107748740 ---- /dev/null -+++ b/libbb/mntent_r.c -@@ -0,0 +1,288 @@ -+/* Utilities for reading/writing fstab, mtab, etc. -+ Copyright (C) 1995-2000, 2001, 2002, 2003, 2006, 2010, 2011 -+ Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+// file extracted from patch 'Bionic Patch V1.0 (Vitaly Greck)': -+// https://busybox-android.googlecode.com/files/patch -+// -+// looks like its based on misc/mntent_r.c from glibc, -+// contains all fixes in current master (2012-03-19), -+// but is not source identical (mostly stuff removed) -+// using the upstream one fails to build -+ -+ -+#include -+#include -+#include -+#include -+#include -+ -+ -+/* Prepare to begin reading and/or writing mount table entries from the -+ beginning of FILE. MODE is as for `fopen'. */ -+FILE *setmntent (const char *file, const char *mode) -+{ -+ /* Extend the mode parameter with "c" to disable cancellation in the -+ I/O functions and "e" to set FD_CLOEXEC. */ -+ size_t modelen = strlen (mode); -+ char newmode[modelen + 3]; -+ memcpy (newmode, mode, modelen); -+ memcpy (newmode + modelen, "ce", 3); -+ FILE *result = fopen (file, newmode); -+ -+ return result; -+} -+ -+ -+/* Close a stream opened with `setmntent'. */ -+int endmntent (FILE *stream) -+{ -+ if (stream) /* SunOS 4.x allows for NULL stream */ -+ fclose (stream); -+ return 1; /* SunOS 4.x says to always return 1 */ -+} -+ -+ -+/* Since the values in a line are separated by spaces, a name cannot -+ contain a space. Therefore some programs encode spaces in names -+ by the strings "\040". We undo the encoding when reading an entry. -+ The decoding happens in place. */ -+static char * -+decode_name (char *buf) -+{ -+ char *rp = buf; -+ char *wp = buf; -+ -+ do -+ if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '4' && rp[3] == '0') -+ { -+ /* \040 is a SPACE. */ -+ *wp++ = ' '; -+ rp += 3; -+ } -+ else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '1') -+ { -+ /* \011 is a TAB. */ -+ *wp++ = '\t'; -+ rp += 3; -+ } -+ else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '2') -+ { -+ /* \012 is a NEWLINE. */ -+ *wp++ = '\n'; -+ rp += 3; -+ } -+ else if (rp[0] == '\\' && rp[1] == '\\') -+ { -+ /* We have to escape \\ to be able to represent all characters. */ -+ *wp++ = '\\'; -+ rp += 1; -+ } -+ else if (rp[0] == '\\' && rp[1] == '1' && rp[2] == '3' && rp[3] == '4') -+ { -+ /* \134 is also \\. */ -+ *wp++ = '\\'; -+ rp += 3; -+ } -+ else -+ *wp++ = *rp; -+ while (*rp++ != '\0'); -+ -+ return buf; -+} -+ -+ -+/* Read one mount table entry from STREAM. Returns a pointer to storage -+ reused on the next call, or null for EOF or error (use feof/ferror to -+ check). */ -+struct mntent *getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz) -+{ -+ char *cp; -+ char *head; -+ -+ do -+ { -+ char *end_ptr; -+ -+ if (fgets (buffer, bufsiz, stream) == NULL) -+ { -+ return NULL; -+ } -+ -+ end_ptr = strchr (buffer, '\n'); -+ if (end_ptr != NULL) /* chop newline */ -+ *end_ptr = '\0'; -+ else -+ { -+ /* Not the whole line was read. Do it now but forget it. */ -+ char tmp[1024]; -+ while (fgets (tmp, sizeof tmp, stream) != NULL) -+ if (strchr (tmp, '\n') != NULL) -+ break; -+ } -+ -+ head = buffer + strspn (buffer, " \t"); -+ /* skip empty lines and comment lines: */ -+ } -+ while (head[0] == '\0' || head[0] == '#'); -+ -+ cp = strsep (&head, " \t"); -+ mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) ""; -+ if (head) -+ head += strspn (head, " \t"); -+ cp = strsep (&head, " \t"); -+ mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) ""; -+ if (head) -+ head += strspn (head, " \t"); -+ cp = strsep (&head, " \t"); -+ mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) ""; -+ if (head) -+ head += strspn (head, " \t"); -+ cp = strsep (&head, " \t"); -+ mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) ""; -+ switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, &mp->mnt_passno) : 0) -+ { -+ case 0: -+ mp->mnt_freq = 0; -+ case 1: -+ mp->mnt_passno = 0; -+ case 2: -+ break; -+ } -+ -+ return mp; -+} -+ -+struct mntent *getmntent (FILE *stream) -+{ -+ static struct mntent m; -+ static char *getmntent_buffer; -+ -+ #define BUFFER_SIZE 4096 -+ if (getmntent_buffer == NULL) { -+ getmntent_buffer = (char *) malloc (BUFFER_SIZE); -+ } -+ -+ return getmntent_r (stream, &m, getmntent_buffer, BUFFER_SIZE); -+ #undef BUFFER_SIZE -+} -+ -+ -+/* We have to use an encoding for names if they contain spaces or tabs. -+ To be able to represent all characters we also have to escape the -+ backslash itself. This "function" must be a macro since we use -+ `alloca'. */ -+#define encode_name(name) \ -+ do { \ -+ const char *rp = name; \ -+ \ -+ while (*rp != '\0') \ -+ if (*rp == ' ' || *rp == '\t' || *rp == '\n' || *rp == '\\') \ -+ break; \ -+ else \ -+ ++rp; \ -+ \ -+ if (*rp != '\0') \ -+ { \ -+ /* In the worst case the length of the string can increase to \ -+ four times the current length. */ \ -+ char *wp; \ -+ \ -+ rp = name; \ -+ name = wp = (char *) alloca (strlen (name) * 4 + 1); \ -+ \ -+ do \ -+ if (*rp == ' ') \ -+ { \ -+ *wp++ = '\\'; \ -+ *wp++ = '0'; \ -+ *wp++ = '4'; \ -+ *wp++ = '0'; \ -+ } \ -+ else if (*rp == '\t') \ -+ { \ -+ *wp++ = '\\'; \ -+ *wp++ = '0'; \ -+ *wp++ = '1'; \ -+ *wp++ = '1'; \ -+ } \ -+ else if (*rp == '\n') \ -+ { \ -+ *wp++ = '\\'; \ -+ *wp++ = '0'; \ -+ *wp++ = '1'; \ -+ *wp++ = '2'; \ -+ } \ -+ else if (*rp == '\\') \ -+ { \ -+ *wp++ = '\\'; \ -+ *wp++ = '\\'; \ -+ } \ -+ else \ -+ *wp++ = *rp; \ -+ while (*rp++ != '\0'); \ -+ } \ -+ } while (0) -+ -+ -+/* Write the mount table entry described by MNT to STREAM. -+ Return zero on success, nonzero on failure. */ -+int addmntent (FILE *stream, const struct mntent *mnt) -+{ -+ struct mntent mntcopy = *mnt; -+ if (fseek (stream, 0, SEEK_END)) -+ return 1; -+ -+ /* Encode spaces and tabs in the names. */ -+ encode_name (mntcopy.mnt_fsname); -+ encode_name (mntcopy.mnt_dir); -+ encode_name (mntcopy.mnt_type); -+ encode_name (mntcopy.mnt_opts); -+ -+ return (fprintf (stream, "%s %s %s %s %d %d\n", -+ mntcopy.mnt_fsname, -+ mntcopy.mnt_dir, -+ mntcopy.mnt_type, -+ mntcopy.mnt_opts, -+ mntcopy.mnt_freq, -+ mntcopy.mnt_passno) < 0 -+ || fflush (stream) != 0); -+} -+ -+ -+/* Search MNT->mnt_opts for an option matching OPT. -+ Returns the address of the substring, or null if none found. */ -+char *hasmntopt (const struct mntent *mnt, const char *opt) -+{ -+ const size_t optlen = strlen (opt); -+ char *rest = mnt->mnt_opts, *p; -+ -+ while ((p = strstr (rest, opt)) != NULL) -+ { -+ if ((p == rest || p[-1] == ',') -+ && (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ',')) -+ return p; -+ -+ rest = strchr (p, ','); -+ if (rest == NULL) -+ break; -+ ++rest; -+ } -+ -+ return NULL; -+} --- -2.45.2 - diff --git a/patches/0013-fix-ipcs-ipcrm-no-sys-sem-shm-msg-etc.patch b/patches/0003-fix-ipcs-ipcrm-no-sys-sem-shm-msg-etc.patch similarity index 91% rename from patches/0013-fix-ipcs-ipcrm-no-sys-sem-shm-msg-etc.patch rename to patches/0003-fix-ipcs-ipcrm-no-sys-sem-shm-msg-etc.patch index 827f1ec..cd76c79 100644 --- a/patches/0013-fix-ipcs-ipcrm-no-sys-sem-shm-msg-etc.patch +++ b/patches/0003-fix-ipcs-ipcrm-no-sys-sem-shm-msg-etc.patch @@ -1,7 +1,7 @@ -From 187cfa9753417e5033aa8893ca4e0299c934ebac Mon Sep 17 00:00:00 2001 +From 9cf0fa6cd156d864a738c21d34ee273392c56dfc Mon Sep 17 00:00:00 2001 From: Tias Guns Date: Tue, 20 Mar 2012 21:26:07 +0000 -Subject: [PATCH 13/35] fix ipcs, ipcrm no sys/sem-shm-msg, etc +Subject: [PATCH 03/17] fix ipcs, ipcrm no sys/sem-shm-msg, etc patch from 'no-sys-shm,msg,sem' by Dan Drown http://dan.drown.org/android/src/busybox/ diff --git a/patches/0004-Bionic-does-not-have-ether_hostton.patch b/patches/0004-Bionic-does-not-have-ether_hostton.patch new file mode 100644 index 0000000..bbaf691 --- /dev/null +++ b/patches/0004-Bionic-does-not-have-ether_hostton.patch @@ -0,0 +1,25 @@ +From 41a741b2213a0f127c239e163d1f8f894f5390f6 Mon Sep 17 00:00:00 2001 +From: topjohnwu +Date: Sat, 13 Jul 2024 18:35:56 -0700 +Subject: [PATCH 04/17] Bionic does not have ether_hostton + +--- + networking/ether-wake.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/networking/ether-wake.c b/networking/ether-wake.c +index 36e90acfb..0bbf2057f 100644 +--- a/networking/ether-wake.c ++++ b/networking/ether-wake.c +@@ -130,7 +130,7 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) + eap = ether_aton_r(hostid, eaddr); + if (eap) { + bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eap)); +-#if !defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30) ++#if !defined(__BIONIC__) && (!defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)) + } else if (ether_hostton(hostid, eaddr) == 0) { + bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr)); + #endif +-- +2.45.2 + diff --git a/patches/0004-eject-add-missing-headers.patch b/patches/0004-eject-add-missing-headers.patch deleted file mode 100644 index abd3895..0000000 --- a/patches/0004-eject-add-missing-headers.patch +++ /dev/null @@ -1,530 +0,0 @@ -From f753b7bd2c777ff5b31c5faba49537c7095e1614 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Thu, 3 Dec 2015 17:01:57 -0400 -Subject: [PATCH 04/35] eject: add missing headers - -Imported from dorimanx's combined ported header toolchain: -https://github.com/dorimanx/android-busybox-ndk ---- - include/scsi/scsi.h | 225 ++++++++++++++++++++++++++++++++++++ - include/scsi/sg.h | 276 ++++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 501 insertions(+) - create mode 100644 include/scsi/scsi.h - create mode 100644 include/scsi/sg.h - -diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h -new file mode 100644 -index 000000000..06377ab00 ---- /dev/null -+++ b/include/scsi/scsi.h -@@ -0,0 +1,225 @@ -+/* Copyright (C) 1998-2015 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+/* -+ * This header file contains public constants and structures used by -+ * the scsi code for linux. -+ */ -+ -+#ifndef _SCSI_SCSI_H -+#define _SCSI_SCSI_H 1 -+ -+#include -+ -+/* -+ * SCSI opcodes -+ */ -+ -+#define TEST_UNIT_READY 0x00 -+#define REZERO_UNIT 0x01 -+#define REQUEST_SENSE 0x03 -+#define FORMAT_UNIT 0x04 -+#define READ_BLOCK_LIMITS 0x05 -+#define REASSIGN_BLOCKS 0x07 -+#define READ_6 0x08 -+#define WRITE_6 0x0a -+#define SEEK_6 0x0b -+#define READ_REVERSE 0x0f -+#define WRITE_FILEMARKS 0x10 -+#define SPACE 0x11 -+#define INQUIRY 0x12 -+#define RECOVER_BUFFERED_DATA 0x14 -+#define MODE_SELECT 0x15 -+#define RESERVE 0x16 -+#define RELEASE 0x17 -+#define COPY 0x18 -+#define ERASE 0x19 -+#define MODE_SENSE 0x1a -+#define START_STOP 0x1b -+#define RECEIVE_DIAGNOSTIC 0x1c -+#define SEND_DIAGNOSTIC 0x1d -+#define ALLOW_MEDIUM_REMOVAL 0x1e -+ -+#define SET_WINDOW 0x24 -+#define READ_CAPACITY 0x25 -+#define READ_10 0x28 -+#define WRITE_10 0x2a -+#define SEEK_10 0x2b -+#define WRITE_VERIFY 0x2e -+#define VERIFY 0x2f -+#define SEARCH_HIGH 0x30 -+#define SEARCH_EQUAL 0x31 -+#define SEARCH_LOW 0x32 -+#define SET_LIMITS 0x33 -+#define PRE_FETCH 0x34 -+#define READ_POSITION 0x34 -+#define SYNCHRONIZE_CACHE 0x35 -+#define LOCK_UNLOCK_CACHE 0x36 -+#define READ_DEFECT_DATA 0x37 -+#define MEDIUM_SCAN 0x38 -+#define COMPARE 0x39 -+#define COPY_VERIFY 0x3a -+#define WRITE_BUFFER 0x3b -+#define READ_BUFFER 0x3c -+#define UPDATE_BLOCK 0x3d -+#define READ_LONG 0x3e -+#define WRITE_LONG 0x3f -+#define CHANGE_DEFINITION 0x40 -+#define WRITE_SAME 0x41 -+#define READ_TOC 0x43 -+#define LOG_SELECT 0x4c -+#define LOG_SENSE 0x4d -+#define MODE_SELECT_10 0x55 -+#define RESERVE_10 0x56 -+#define RELEASE_10 0x57 -+#define MODE_SENSE_10 0x5a -+#define PERSISTENT_RESERVE_IN 0x5e -+#define PERSISTENT_RESERVE_OUT 0x5f -+#define MOVE_MEDIUM 0xa5 -+#define READ_12 0xa8 -+#define WRITE_12 0xaa -+#define WRITE_VERIFY_12 0xae -+#define SEARCH_HIGH_12 0xb0 -+#define SEARCH_EQUAL_12 0xb1 -+#define SEARCH_LOW_12 0xb2 -+#define READ_ELEMENT_STATUS 0xb8 -+#define SEND_VOLUME_TAG 0xb6 -+#define WRITE_LONG_2 0xea -+ -+/* -+ * Status codes -+ */ -+ -+#define GOOD 0x00 -+#define CHECK_CONDITION 0x01 -+#define CONDITION_GOOD 0x02 -+#define BUSY 0x04 -+#define INTERMEDIATE_GOOD 0x08 -+#define INTERMEDIATE_C_GOOD 0x0a -+#define RESERVATION_CONFLICT 0x0c -+#define COMMAND_TERMINATED 0x11 -+#define QUEUE_FULL 0x14 -+ -+#define STATUS_MASK 0x3e -+ -+/* -+ * SENSE KEYS -+ */ -+ -+#define NO_SENSE 0x00 -+#define RECOVERED_ERROR 0x01 -+#define NOT_READY 0x02 -+#define MEDIUM_ERROR 0x03 -+#define HARDWARE_ERROR 0x04 -+#define ILLEGAL_REQUEST 0x05 -+#define UNIT_ATTENTION 0x06 -+#define DATA_PROTECT 0x07 -+#define BLANK_CHECK 0x08 -+#define COPY_ABORTED 0x0a -+#define ABORTED_COMMAND 0x0b -+#define VOLUME_OVERFLOW 0x0d -+#define MISCOMPARE 0x0e -+ -+ -+/* -+ * DEVICE TYPES -+ */ -+ -+#define TYPE_DISK 0x00 -+#define TYPE_TAPE 0x01 -+#define TYPE_PROCESSOR 0x03 /* HP scanners use this */ -+#define TYPE_WORM 0x04 /* Treated as ROM by our system */ -+#define TYPE_ROM 0x05 -+#define TYPE_SCANNER 0x06 -+#define TYPE_MOD 0x07 /* Magneto-optical disk - -+ * - treated as TYPE_DISK */ -+#define TYPE_MEDIUM_CHANGER 0x08 -+#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */ -+#define TYPE_NO_LUN 0x7f -+ -+/* -+ * standard mode-select header prepended to all mode-select commands -+ * -+ * moved here from cdrom.h -- kraxel -+ */ -+ -+struct ccs_modesel_head -+ { -+ unsigned char _r1; /* reserved. */ -+ unsigned char medium; /* device-specific medium type. */ -+ unsigned char _r2; /* reserved. */ -+ unsigned char block_desc_length; /* block descriptor length. */ -+ unsigned char density; /* device-specific density code. */ -+ unsigned char number_blocks_hi; /* number of blocks in this block -+ desc. */ -+ unsigned char number_blocks_med; -+ unsigned char number_blocks_lo; -+ unsigned char _r3; -+ unsigned char block_length_hi; /* block length for blocks in this -+ desc. */ -+ unsigned char block_length_med; -+ unsigned char block_length_lo; -+ }; -+ -+/* -+ * MESSAGE CODES -+ */ -+ -+#define COMMAND_COMPLETE 0x00 -+#define EXTENDED_MESSAGE 0x01 -+#define EXTENDED_MODIFY_DATA_POINTER 0x00 -+#define EXTENDED_SDTR 0x01 -+#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ -+#define EXTENDED_WDTR 0x03 -+#define SAVE_POINTERS 0x02 -+#define RESTORE_POINTERS 0x03 -+#define DISCONNECT 0x04 -+#define INITIATOR_ERROR 0x05 -+#define ABORT 0x06 -+#define MESSAGE_REJECT 0x07 -+#define NOP 0x08 -+#define MSG_PARITY_ERROR 0x09 -+#define LINKED_CMD_COMPLETE 0x0a -+#define LINKED_FLG_CMD_COMPLETE 0x0b -+#define BUS_DEVICE_RESET 0x0c -+ -+#define INITIATE_RECOVERY 0x0f /* SCSI-II only */ -+#define RELEASE_RECOVERY 0x10 /* SCSI-II only */ -+ -+#define SIMPLE_QUEUE_TAG 0x20 -+#define HEAD_OF_QUEUE_TAG 0x21 -+#define ORDERED_QUEUE_TAG 0x22 -+ -+/* -+ * Here are some scsi specific ioctl commands which are sometimes useful. -+ */ -+/* These are a few other constants only used by scsi devices. */ -+ -+#define SCSI_IOCTL_GET_IDLUN 0x5382 -+ -+/* Used to turn on and off tagged queuing for scsi devices. */ -+ -+#define SCSI_IOCTL_TAGGED_ENABLE 0x5383 -+#define SCSI_IOCTL_TAGGED_DISABLE 0x5384 -+ -+/* Used to obtain the host number of a device. */ -+#define SCSI_IOCTL_PROBE_HOST 0x5385 -+ -+/* Used to get the bus number for a device. */ -+#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386 -+ -+#endif /* scsi/scsi.h */ -diff --git a/include/scsi/sg.h b/include/scsi/sg.h -new file mode 100644 -index 000000000..767945236 ---- /dev/null -+++ b/include/scsi/sg.h -@@ -0,0 +1,276 @@ -+/* Copyright (C) 1997-2015 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+/* -+ History: -+ Started: Aug 9 by Lawrence Foard (entropy@world.std.com), to allow user -+ process control of SCSI devices. -+ Development Sponsored by Killy Corp. NY NY -+*/ -+ -+#ifndef _SCSI_SG_H -+#define _SCSI_SG_H 1 -+ -+#include -+#define __need_size_t -+#include -+ -+ -+/* New interface introduced in the 3.x SG drivers follows */ -+ -+/* Same structure as used by readv() Linux system call. It defines one -+ scatter-gather element. */ -+typedef struct sg_iovec -+{ -+ void * iov_base; /* Starting address */ -+ size_t iov_len; /* Length in bytes */ -+} sg_iovec_t; -+ -+ -+typedef struct sg_io_hdr -+{ -+ int interface_id; /* [i] 'S' for SCSI generic (required) */ -+ int dxfer_direction; /* [i] data transfer direction */ -+ unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ -+ unsigned char mx_sb_len; /* [i] max length to write to sbp */ -+ unsigned short int iovec_count; /* [i] 0 implies no scatter gather */ -+ unsigned int dxfer_len; /* [i] byte count of data transfer */ -+ void * dxferp; /* [i], [*io] points to data transfer memory -+ or scatter gather list */ -+ unsigned char * cmdp; /* [i], [*i] points to command to perform */ -+ unsigned char * sbp; /* [i], [*o] points to sense_buffer memory */ -+ unsigned int timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ -+ unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */ -+ int pack_id; /* [i->o] unused internally (normally) */ -+ void * usr_ptr; /* [i->o] unused internally */ -+ unsigned char status; /* [o] scsi status */ -+ unsigned char masked_status;/* [o] shifted, masked scsi status */ -+ unsigned char msg_status; /* [o] messaging level data (optional) */ -+ unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ -+ unsigned short int host_status; /* [o] errors from host adapter */ -+ unsigned short int driver_status;/* [o] errors from software driver */ -+ int resid; /* [o] dxfer_len - actual_transferred */ -+ unsigned int duration; /* [o] time taken by cmd (unit: millisec) */ -+ unsigned int info; /* [o] auxiliary information */ -+} sg_io_hdr_t; -+ -+ -+/* Use negative values to flag difference from original sg_header structure. */ -+#define SG_DXFER_NONE -1 /* e.g. a SCSI Test Unit Ready command */ -+#define SG_DXFER_TO_DEV -2 /* e.g. a SCSI WRITE command */ -+#define SG_DXFER_FROM_DEV -3 /* e.g. a SCSI READ command */ -+#define SG_DXFER_TO_FROM_DEV -4 /* treated like SG_DXFER_FROM_DEV with the -+ additional property than during indirect -+ IO the user buffer is copied into the -+ kernel buffers before the transfer */ -+ -+ -+/* following flag values can be "or"-ed together */ -+#define SG_FLAG_DIRECT_IO 1 /* default is indirect IO */ -+#define SG_FLAG_LUN_INHIBIT 2 /* default is to put device's lun into */ -+ /* the 2nd byte of SCSI command */ -+#define SG_FLAG_NO_DXFER 0x10000 /* no transfer of kernel buffers to/from */ -+ /* user space (debug indirect IO) */ -+ -+/* The following 'info' values are "or"-ed together. */ -+#define SG_INFO_OK_MASK 0x1 -+#define SG_INFO_OK 0x0 /* no sense, host nor driver "noise" */ -+#define SG_INFO_CHECK 0x1 /* something abnormal happened */ -+ -+#define SG_INFO_DIRECT_IO_MASK 0x6 -+#define SG_INFO_INDIRECT_IO 0x0 /* data xfer via kernel buffers (or no xfer) */ -+#define SG_INFO_DIRECT_IO 0x2 /* direct IO requested and performed */ -+#define SG_INFO_MIXED_IO 0x4 /* part direct, part indirect IO */ -+ -+ -+/* Request information about a specific SG device, used by -+ SG_GET_SCSI_ID ioctl (). */ -+struct sg_scsi_id { -+ /* Host number as in "scsi" where 'n' is one of 0, 1, 2 etc. */ -+ int host_no; -+ int channel; -+ /* SCSI id of target device. */ -+ int scsi_id; -+ int lun; -+ /* TYPE_... defined in . */ -+ int scsi_type; -+ /* Host (adapter) maximum commands per lun. */ -+ short int h_cmd_per_lun; -+ /* Device (or adapter) maximum queue length. */ -+ short int d_queue_depth; -+ /* Unused, set to 0 for now. */ -+ int unused[2]; -+}; -+ -+/* Used by SG_GET_REQUEST_TABLE ioctl(). */ -+typedef struct sg_req_info { -+ char req_state; /* 0 -> not used, 1 -> written, 2 -> ready to read */ -+ char orphan; /* 0 -> normal request, 1 -> from interruped SG_IO */ -+ char sg_io_owned; /* 0 -> complete with read(), 1 -> owned by SG_IO */ -+ char problem; /* 0 -> no problem detected, 1 -> error to report */ -+ int pack_id; /* pack_id associated with request */ -+ void * usr_ptr; /* user provided pointer (in new interface) */ -+ unsigned int duration; /* millisecs elapsed since written (req_state==1) -+ or request duration (req_state==2) */ -+ int unused; -+} sg_req_info_t; -+ -+ -+/* IOCTLs: Those ioctls that are relevant to the SG 3.x drivers follow. -+ [Those that only apply to the SG 2.x drivers are at the end of the file.] -+ (_GET_s yield result via 'int *' 3rd argument unless otherwise indicated) */ -+ -+#define SG_EMULATED_HOST 0x2203 /* true for emulated host adapter (ATAPI) */ -+ -+/* Used to configure SCSI command transformation layer for ATAPI devices */ -+/* Only supported by the ide-scsi driver */ -+#define SG_SET_TRANSFORM 0x2204 /* N.B. 3rd arg is not pointer but value: */ -+ /* 3rd arg = 0 to disable transform, 1 to enable it */ -+#define SG_GET_TRANSFORM 0x2205 -+ -+#define SG_SET_RESERVED_SIZE 0x2275 /* request a new reserved buffer size */ -+#define SG_GET_RESERVED_SIZE 0x2272 /* actual size of reserved buffer */ -+ -+/* The following ioctl has a 'sg_scsi_id_t *' object as its 3rd argument. */ -+#define SG_GET_SCSI_ID 0x2276 /* Yields fd's bus, chan, dev, lun + type */ -+/* SCSI id information can also be obtained from SCSI_IOCTL_GET_IDLUN */ -+ -+/* Override host setting and always DMA using low memory ( <16MB on i386) */ -+#define SG_SET_FORCE_LOW_DMA 0x2279 /* 0-> use adapter setting, 1-> force */ -+#define SG_GET_LOW_DMA 0x227a /* 0-> use all ram for dma; 1-> low dma ram */ -+ -+/* When SG_SET_FORCE_PACK_ID set to 1, pack_id is input to read() which -+ tries to fetch a packet with a matching pack_id, waits, or returns EAGAIN. -+ If pack_id is -1 then read oldest waiting. When ...FORCE_PACK_ID set to 0 -+ then pack_id ignored by read() and oldest readable fetched. */ -+#define SG_SET_FORCE_PACK_ID 0x227b -+#define SG_GET_PACK_ID 0x227c /* Yields oldest readable pack_id (or -1) */ -+ -+#define SG_GET_NUM_WAITING 0x227d /* Number of commands awaiting read() */ -+ -+/* Yields max scatter gather tablesize allowed by current host adapter */ -+#define SG_GET_SG_TABLESIZE 0x227F /* 0 implies can't do scatter gather */ -+ -+#define SG_GET_VERSION_NUM 0x2282 /* Example: version 2.1.34 yields 20134 */ -+ -+/* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */ -+#define SG_SCSI_RESET 0x2284 -+/* Associated values that can be given to SG_SCSI_RESET follow */ -+#define SG_SCSI_RESET_NOTHING 0 -+#define SG_SCSI_RESET_DEVICE 1 -+#define SG_SCSI_RESET_BUS 2 -+#define SG_SCSI_RESET_HOST 3 -+ -+/* synchronous SCSI command ioctl, (only in version 3 interface) */ -+#define SG_IO 0x2285 /* similar effect as write() followed by read() */ -+ -+#define SG_GET_REQUEST_TABLE 0x2286 /* yields table of active requests */ -+ -+/* How to treat EINTR during SG_IO ioctl(), only in SG 3.x series */ -+#define SG_SET_KEEP_ORPHAN 0x2287 /* 1 -> hold for read(), 0 -> drop (def) */ -+#define SG_GET_KEEP_ORPHAN 0x2288 -+ -+ -+#define SG_SCATTER_SZ (8 * 4096) /* PAGE_SIZE not available to user */ -+/* Largest size (in bytes) a single scatter-gather list element can have. -+ The value must be a power of 2 and <= (PAGE_SIZE * 32) [131072 bytes on -+ i386]. The minimum value is PAGE_SIZE. If scatter-gather not supported -+ by adapter then this value is the largest data block that can be -+ read/written by a single scsi command. The user can find the value of -+ PAGE_SIZE by calling getpagesize() defined in unistd.h . */ -+ -+#define SG_DEFAULT_RETRIES 1 -+ -+/* Defaults, commented if they differ from original sg driver */ -+#define SG_DEF_FORCE_LOW_DMA 0 /* was 1 -> memory below 16MB on i386 */ -+#define SG_DEF_FORCE_PACK_ID 0 -+#define SG_DEF_KEEP_ORPHAN 0 -+#define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ /* load time option */ -+ -+/* maximum outstanding requests, write() yields EDOM if exceeded */ -+#define SG_MAX_QUEUE 16 -+ -+#define SG_BIG_BUFF SG_DEF_RESERVED_SIZE /* for backward compatibility */ -+ -+/* Alternate style type names, "..._t" variants preferred */ -+typedef struct sg_io_hdr Sg_io_hdr; -+typedef struct sg_io_vec Sg_io_vec; -+typedef struct sg_scsi_id Sg_scsi_id; -+typedef struct sg_req_info Sg_req_info; -+ -+ -+/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */ -+/* The older SG interface based on the 'sg_header' structure follows. */ -+/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ -+ -+#define SG_MAX_SENSE 16 /* this only applies to the sg_header interface */ -+ -+struct sg_header -+ { -+ /* Length of incoming packet (including header). */ -+ int pack_len; -+ /* Maximal length of expected reply. */ -+ int reply_len; -+ /* Id number of packet. */ -+ int pack_id; -+ /* 0==ok, otherwise error number. */ -+ int result; -+ /* Force 12 byte command length for group 6 & 7 commands. */ -+ unsigned int twelve_byte:1; -+ /* SCSI status from target. */ -+ unsigned int target_status:5; -+ /* Host status (see "DID" codes). */ -+ unsigned int host_status:8; -+ /* Driver status+suggestion. */ -+ unsigned int driver_status:8; -+ /* Unused. */ -+ unsigned int other_flags:10; -+ /* Output in 3 cases: -+ when target_status is CHECK_CONDITION or -+ when target_status is COMMAND_TERMINATED or -+ when (driver_status & DRIVER_SENSE) is true. */ -+ unsigned char sense_buffer[SG_MAX_SENSE]; -+ }; -+ -+ -+/* IOCTLs: The following are not required (or ignored) when the sg_io_hdr_t -+ interface is used. They are kept for backward compatibility with -+ the original and version 2 drivers. */ -+ -+#define SG_SET_TIMEOUT 0x2201 /* Set timeout; *(int *)arg==timeout. */ -+#define SG_GET_TIMEOUT 0x2202 /* Get timeout; return timeout. */ -+ -+/* Get/set command queuing state per fd (default is SG_DEF_COMMAND_Q). */ -+#define SG_GET_COMMAND_Q 0x2270 /* Yields 0 (queuing off) or 1 (on). */ -+#define SG_SET_COMMAND_Q 0x2271 /* Change queuing state with 0 or 1. */ -+ -+/* Turn on error sense trace (1..8), dump this device to log/console (9) -+ or dump all sg device states ( >9 ) to log/console. */ -+#define SG_SET_DEBUG 0x227e /* 0 -> turn off debug */ -+ -+#define SG_NEXT_CMD_LEN 0x2283 /* Override SCSI command length with given -+ number on the next write() on this file -+ descriptor. */ -+ -+/* Defaults, commented if they differ from original sg driver */ -+#define SG_DEFAULT_TIMEOUT (60*HZ) /* HZ == 'jiffies in 1 second' */ -+#define SG_DEF_COMMAND_Q 0 /* command queuing is always on when -+ the new interface is used */ -+#define SG_DEF_UNDERRUN_FLAG 0 -+ -+ -+#endif /* scsi/sg.h */ --- -2.45.2 - diff --git a/patches/0005-Prevent-duplicate-in6_ifreq-definition.patch b/patches/0005-Prevent-duplicate-in6_ifreq-definition.patch new file mode 100644 index 0000000..427f773 --- /dev/null +++ b/patches/0005-Prevent-duplicate-in6_ifreq-definition.patch @@ -0,0 +1,45 @@ +From 79bdb8978e9ffcfc4799ed00206602d5e57b5844 Mon Sep 17 00:00:00 2001 +From: topjohnwu +Date: Sun, 14 Jul 2024 16:54:36 -0700 +Subject: [PATCH 05/17] Prevent duplicate in6_ifreq definition + +--- + networking/ifconfig.c | 8 -------- + networking/interface.c | 2 +- + 2 files changed, 1 insertion(+), 9 deletions(-) + +diff --git a/networking/ifconfig.c b/networking/ifconfig.c +index 9ee232a66..06898b6d2 100644 +--- a/networking/ifconfig.c ++++ b/networking/ifconfig.c +@@ -127,14 +127,6 @@ + # define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */ + #endif + +-#if ENABLE_FEATURE_IPV6 +-struct in6_ifreq { +- struct in6_addr ifr6_addr; +- uint32_t ifr6_prefixlen; +- int ifr6_ifindex; +-}; +-#endif +- + /* + * Here are the bit masks for the "flags" member of struct options below. + * N_ signifies no arg prefix; M_ signifies arg prefixed by '-'. +diff --git a/networking/interface.c b/networking/interface.c +index 6b6c0944a..cf48733da 100644 +--- a/networking/interface.c ++++ b/networking/interface.c +@@ -54,7 +54,7 @@ + #define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6" + + #ifdef HAVE_AFINET6 +-# ifndef _LINUX_IN6_H ++# ifndef _UAPI_IPV6_H + /* + * This is from linux/include/net/ipv6.h + */ +-- +2.45.2 + diff --git a/patches/0005-fix-udhcpd-and-nameif-add-ether_ntoa_r-and-ether_ato.patch b/patches/0005-fix-udhcpd-and-nameif-add-ether_ntoa_r-and-ether_ato.patch deleted file mode 100644 index 43ea9a6..0000000 --- a/patches/0005-fix-udhcpd-and-nameif-add-ether_ntoa_r-and-ether_ato.patch +++ /dev/null @@ -1,253 +0,0 @@ -From b454f643056e7b0e7799f202370e0a2ec3893665 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Tue, 10 Jan 2017 10:24:29 -0400 -Subject: [PATCH 05/35] fix udhcpd and nameif, add ether_ntoa_r and - ether_aton_r from glibc - -this patch also fixes part of arping and ether-wake, but not sufficiently yet - -Patch modified by Tias Guns from 'ether_XtoY-from-glibc' by Dan Drown -http://dan.drown.org/android/src/busybox/ -Rebased for busybox 1.26.1 by Chris Renshaw ---- - networking/arping.c | 1 + - networking/ether-wake.c | 6 ++-- - networking/ether_aton_r.c | 63 +++++++++++++++++++++++++++++++++++++ - networking/ether_ntoa_r.c | 33 +++++++++++++++++++ - networking/ether_port.h | 29 +++++++++++++++++ - networking/nameif.c | 1 + - networking/udhcp/Kbuild.src | 1 + - networking/udhcp/dhcpd.c | 4 +++ - 8 files changed, 136 insertions(+), 2 deletions(-) - create mode 100644 networking/ether_aton_r.c - create mode 100644 networking/ether_ntoa_r.c - create mode 100644 networking/ether_port.h - -diff --git a/networking/arping.c b/networking/arping.c -index 86f0221ed..6a1b8bae1 100644 ---- a/networking/arping.c -+++ b/networking/arping.c -@@ -14,6 +14,7 @@ - //applet:IF_ARPING(APPLET(arping, BB_DIR_USR_SBIN, BB_SUID_DROP)) - - //kbuild:lib-$(CONFIG_ARPING) += arping.o -+//kbuild:lib-$(CONFIG_ARPING) += ether_ntoa_r.o - - //usage:#define arping_trivial_usage - //usage: "[-fqbDUA] [-c CNT] [-w TIMEOUT] [-I IFACE] [-s SRC_IP] DST_IP" -diff --git a/networking/ether-wake.c b/networking/ether-wake.c -index 36e90acfb..809c0d9f0 100644 ---- a/networking/ether-wake.c -+++ b/networking/ether-wake.c -@@ -72,6 +72,7 @@ - //applet:IF_ETHER_WAKE(APPLET_ODDNAME(ether-wake, ether_wake, BB_DIR_USR_SBIN, BB_SUID_DROP, ether_wake)) - - //kbuild:lib-$(CONFIG_ETHER_WAKE) += ether-wake.o -+//kbuild:lib-$(CONFIG_ETHER_WAKE) += ether_aton_r.o ether_ntoa_r.o - - //usage:#define ether_wake_trivial_usage - //usage: "[-b] [-i IFACE] [-p aa:bb:cc:dd[:ee:ff]/a.b.c.d] MAC" -@@ -126,13 +127,14 @@ void bb_debug_dump_packet(unsigned char *outpack, int pktsize) - static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) - { - struct ether_addr *eap; -+ char ether_buf[20]; - - eap = ether_aton_r(hostid, eaddr); - if (eap) { -- bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eap)); -+ bb_debug_msg("The target station address is %s\n\n", ether_ntoa_r(eap, ether_buf)); - #if !defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30) - } else if (ether_hostton(hostid, eaddr) == 0) { -- bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr)); -+ bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa_r(eaddr, ether_buf)); - #endif - } else { - bb_show_usage(); -diff --git a/networking/ether_aton_r.c b/networking/ether_aton_r.c -new file mode 100644 -index 000000000..0215f16d4 ---- /dev/null -+++ b/networking/ether_aton_r.c -@@ -0,0 +1,63 @@ -+/* Copyright (C) 1996,97,98,99,2002 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ Contributed by Ulrich Drepper , 1996. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, write to the Free -+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -+ 02111-1307 USA. */ -+ -+#include -+#include -+#include -+#include -+ -+ -+struct ether_addr * -+ether_aton_r (const char *asc, struct ether_addr *addr) -+{ -+ size_t cnt; -+ -+ for (cnt = 0; cnt < 6; ++cnt) -+ { -+ unsigned int number; -+ char ch; -+ -+ ch = tolower (*asc++); -+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) -+ return NULL; -+ number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); -+ -+ ch = tolower (*asc); -+ if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch))) -+ { -+ ++asc; -+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) -+ return NULL; -+ number <<= 4; -+ number += isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); -+ -+ ch = *asc; -+ if (cnt < 5 && ch != ':') -+ return NULL; -+ } -+ -+ /* Store result. */ -+ addr->ether_addr_octet[cnt] = (unsigned char) number; -+ -+ /* Skip ':'. */ -+ ++asc; -+ } -+ -+ return addr; -+} -diff --git a/networking/ether_ntoa_r.c b/networking/ether_ntoa_r.c -new file mode 100644 -index 000000000..cd5061434 ---- /dev/null -+++ b/networking/ether_ntoa_r.c -@@ -0,0 +1,33 @@ -+/* Copyright (C) 1996,97,2002 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ Contributed by Ulrich Drepper , 1996. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, write to the Free -+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -+ 02111-1307 USA. */ -+ -+#include -+#include -+#include -+ -+ -+char * -+ether_ntoa_r (const struct ether_addr *addr, char *buf) -+{ -+ sprintf (buf, "%x:%x:%x:%x:%x:%x", -+ addr->ether_addr_octet[0], addr->ether_addr_octet[1], -+ addr->ether_addr_octet[2], addr->ether_addr_octet[3], -+ addr->ether_addr_octet[4], addr->ether_addr_octet[5]); -+ return buf; -+} -diff --git a/networking/ether_port.h b/networking/ether_port.h -new file mode 100644 -index 000000000..5e0146b29 ---- /dev/null -+++ b/networking/ether_port.h -@@ -0,0 +1,29 @@ -+/* Copyright (C) 1996,97,98,99,2002 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ Contributed by Ulrich Drepper , 1996. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, write to the Free -+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -+ 02111-1307 USA. */ -+ -+#ifndef ETHER_PORT_H -+#define ETHER_PORT_H 1 -+ -+#include -+#include -+ -+struct ether_addr * ether_aton_r (const char *asc, struct ether_addr *addr); -+char * ether_ntoa_r (const struct ether_addr *addr, char *buf); -+ -+#endif /* ETHER_PORT_H */ -diff --git a/networking/nameif.c b/networking/nameif.c -index 66e042688..15a7b9c94 100644 ---- a/networking/nameif.c -+++ b/networking/nameif.c -@@ -41,6 +41,7 @@ - //applet:IF_NAMEIF(APPLET_NOEXEC(nameif, nameif, BB_DIR_SBIN, BB_SUID_DROP, nameif)) - - //kbuild:lib-$(CONFIG_NAMEIF) += nameif.o -+//kbuild:lib-$(CONFIG_NAMEIF) += ether_aton_r.o - - //usage:#define nameif_trivial_usage - //usage: IF_NOT_FEATURE_NAMEIF_EXTENDED( -diff --git a/networking/udhcp/Kbuild.src b/networking/udhcp/Kbuild.src -index fcb725fbc..2d5739c7e 100644 ---- a/networking/udhcp/Kbuild.src -+++ b/networking/udhcp/Kbuild.src -@@ -14,6 +14,7 @@ lib-$(CONFIG_UDHCPD) += common.o packet.o signalpipe.o socket.o - - lib-$(CONFIG_UDHCPC) += dhcpc.o - lib-$(CONFIG_UDHCPD) += dhcpd.o arpping.o -+lib-$(CONFIG_UDHCPD) += ../ether_aton_r.o ../ether_ntoa_r.o - lib-$(CONFIG_DUMPLEASES) += dumpleases.o - lib-$(CONFIG_DHCPRELAY) += dhcprelay.o common.o socket.o packet.o - -diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c -index 66750e2e6..aeebb12f3 100644 ---- a/networking/udhcp/dhcpd.c -+++ b/networking/udhcp/dhcpd.c -@@ -40,8 +40,12 @@ - //usage: "\nSignals:" - //usage: "\n USR1 Update lease file" - -+#include - #include - #include -+ -+#include "../ether_port.h" -+ - #include "common.h" - #include "dhcpc.h" - #include "dhcpd.h" --- -2.45.2 - diff --git a/patches/0006-Add-missing-sigisemptyset-implementation.patch b/patches/0006-Add-missing-sigisemptyset-implementation.patch new file mode 100644 index 0000000..4e648ba --- /dev/null +++ b/patches/0006-Add-missing-sigisemptyset-implementation.patch @@ -0,0 +1,32 @@ +From 1b95c833d8cda62bf79f0ec8da7cca8f3ea1e4d8 Mon Sep 17 00:00:00 2001 +From: topjohnwu +Date: Sun, 14 Jul 2024 16:55:01 -0700 +Subject: [PATCH 06/17] Add missing sigisemptyset implementation + +--- + shell/hush.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/shell/hush.c b/shell/hush.c +index d111f0cc5..5fbceaae3 100644 +--- a/shell/hush.c ++++ b/shell/hush.c +@@ -1942,6 +1942,15 @@ enum { + , + }; + ++#ifdef __BIONIC__ ++static int sigisemptyset(const sigset_t *set) ++{ ++ sigset_t empty; ++ sigemptyset(&empty); ++ return memcmp(&empty, set, sizeof(sigset_t)) == 0; ++} ++#endif ++ + static void record_pending_signo(int sig) + { + sigaddset(&G.pending_set, sig); +-- +2.45.2 + diff --git a/patches/0006-fix-ether-wake-avoid-ether_hostton-and-include-if_et.patch b/patches/0006-fix-ether-wake-avoid-ether_hostton-and-include-if_et.patch deleted file mode 100644 index e4379a1..0000000 --- a/patches/0006-fix-ether-wake-avoid-ether_hostton-and-include-if_et.patch +++ /dev/null @@ -1,38 +0,0 @@ -From fa9b786d8c34bcaf61a3dfdd20138c6172e02755 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Wed, 2 Dec 2015 23:44:06 -0400 -Subject: [PATCH 06/35] fix ether-wake, avoid ether_hostton and include - if_ether - -Patch by Tias Guns , based on 'no-ether_hostton' by Dan Drown -"there is no /etc/ethers or ether_hostton on bionic" -http://dan.drown.org/android/src/busybox/ -Rebased for busybox 1.24.1 by Chris Renshaw ---- - networking/ether-wake.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/networking/ether-wake.c b/networking/ether-wake.c -index 809c0d9f0..920f0c4a0 100644 ---- a/networking/ether-wake.c -+++ b/networking/ether-wake.c -@@ -87,6 +87,7 @@ - #include "libbb.h" - #include - #include -+#include - #include - - /* Note: PF_INET, SOCK_DGRAM, IPPROTO_UDP would allow SIOCGIFHWADDR to -@@ -132,7 +133,7 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) - eap = ether_aton_r(hostid, eaddr); - if (eap) { - bb_debug_msg("The target station address is %s\n\n", ether_ntoa_r(eap, ether_buf)); --#if !defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30) -+#if !defined(__BIONIC__) && (!defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)) - } else if (ether_hostton(hostid, eaddr) == 0) { - bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa_r(eaddr, ether_buf)); - #endif --- -2.45.2 - diff --git a/patches/0007-Prevent-compiling-mtab-related-features.patch b/patches/0007-Prevent-compiling-mtab-related-features.patch new file mode 100644 index 0000000..3f4929f --- /dev/null +++ b/patches/0007-Prevent-compiling-mtab-related-features.patch @@ -0,0 +1,34 @@ +From f258400ac6119a369865606883245ecf176005ae Mon Sep 17 00:00:00 2001 +From: topjohnwu +Date: Sun, 14 Jul 2024 21:26:56 -0700 +Subject: [PATCH 07/17] Prevent compiling mtab related features + +--- + util-linux/mount.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/util-linux/mount.c b/util-linux/mount.c +index 4e65b6b46..08058db49 100644 +--- a/util-linux/mount.c ++++ b/util-linux/mount.c +@@ -768,7 +768,8 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero + // If the mount was successful, and we're maintaining an old-style + // mtab file by hand, add the new entry to it now. + mtab: +- if (USE_MTAB && !rc && !(vfsflags & MS_REMOUNT)) { ++ #if USE_MTAB ++ if (!rc && !(vfsflags & MS_REMOUNT)) { + char *fsname; + FILE *mountTable = setmntent(bb_path_mtab_file, "a+"); + const char *option_str = mount_option_str; +@@ -814,6 +815,7 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero + free(fsname); + } + } ++#endif // USE_MTAB + ret: + return rc; + } +-- +2.45.2 + diff --git a/patches/0008-Remove-CBQ-support-from-tc.patch b/patches/0008-Remove-CBQ-support-from-tc.patch new file mode 100644 index 0000000..54a838c --- /dev/null +++ b/patches/0008-Remove-CBQ-support-from-tc.patch @@ -0,0 +1,64 @@ +From 12334c3e19a1e902a90b7d4898f61b08301de94d Mon Sep 17 00:00:00 2001 +From: topjohnwu +Date: Mon, 15 Jul 2024 18:50:57 -0700 +Subject: [PATCH 08/17] Remove CBQ support from tc + +CBQ support is removed from Linux. +More info: https://bugs.busybox.net/show_bug.cgi?id=15931 +--- + networking/tc.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/networking/tc.c b/networking/tc.c +index 43187f7ee..92601d6e3 100644 +--- a/networking/tc.c ++++ b/networking/tc.c +@@ -31,7 +31,7 @@ + //usage: "qdisc [handle QHANDLE] [root|"IF_FEATURE_TC_INGRESS("ingress|")"parent CLASSID]\n" + /* //usage: "[estimator INTERVAL TIME_CONSTANT]\n" */ + //usage: " [[QDISC_KIND] [help|OPTIONS]]\n" +-//usage: " QDISC_KIND := [p|b]fifo|tbf|prio|cbq|red|etc.\n" ++//usage: " QDISC_KIND := [p|b]fifo|tbf|prio|red|etc.\n" + //usage: "qdisc show [dev STRING]"IF_FEATURE_TC_INGRESS(" [ingress]")"\n" + //usage: "class [classid CLASSID] [root|parent CLASSID]\n" + //usage: " [[QDISC_KIND] [help|OPTIONS] ]\n" +@@ -230,7 +230,7 @@ static int cbq_parse_opt(int argc, char **argv, struct nlmsghdr *n) + { + return 0; + } +-#endif ++ + static int cbq_print_opt(struct rtattr *opt) + { + struct rtattr *tb[TCA_CBQ_MAX+1]; +@@ -322,6 +322,7 @@ static int cbq_print_opt(struct rtattr *opt) + done: + return 0; + } ++#endif + + static FAST_FUNC int print_qdisc( + const struct sockaddr_nl *who UNUSED_PARAM, +@@ -373,7 +374,8 @@ static FAST_FUNC int print_qdisc( + if (qqq == 0) { /* pfifo_fast aka prio */ + prio_print_opt(tb[TCA_OPTIONS]); + } else if (qqq == 1) { /* class based queuing */ +- cbq_print_opt(tb[TCA_OPTIONS]); ++ /* cbq_print_opt(tb[TCA_OPTIONS]); */ ++ printf("cbq not supported"); + } else { + /* don't know how to print options for this qdisc */ + printf("(options for %s)", name); +@@ -444,7 +446,8 @@ static FAST_FUNC int print_class( + /* nothing. */ /*prio_print_opt(tb[TCA_OPTIONS]);*/ + } else if (qqq == 1) { /* class based queuing */ + /* cbq_print_copt() is identical to cbq_print_opt(). */ +- cbq_print_opt(tb[TCA_OPTIONS]); ++ /* cbq_print_opt(tb[TCA_OPTIONS]); */ ++ printf("cbq not supported"); + } else { + /* don't know how to print options for this class */ + printf("(options for %s)", name); +-- +2.45.2 + diff --git a/patches/0008-android-syscalls-shmget-msgget-semget.patch b/patches/0008-android-syscalls-shmget-msgget-semget.patch deleted file mode 100644 index dd9cc5f..0000000 --- a/patches/0008-android-syscalls-shmget-msgget-semget.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 9f36b941ea4c5a8f30549cc429fcf12f4462676c Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Mon, 12 Sep 2016 14:45:35 -0300 -Subject: [PATCH 08/35] android syscalls: shmget/msgget/semget - -Patch modified by Tias Guns from 'no-sys-shm,msg,sem' by Dan Drown -http://dan.drown.org/android/src/busybox/ -Rebased for busybox 1.25.0 by Chris Renshaw ---- - libbb/missing_syscalls.c | 15 +++++++++++++++ - 1 file changed, 15 insertions(+) - -diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c -index dc40d9155..82b600ced 100644 ---- a/libbb/missing_syscalls.c -+++ b/libbb/missing_syscalls.c -@@ -31,6 +31,21 @@ int pivot_root(const char *new_root, const char *put_old) - return syscall(__NR_pivot_root, new_root, put_old); - } - -+int shmget(key_t key, size_t size, int shmflg) -+{ -+ return syscall(__NR_shmget, key, size, shmflg); -+} -+ -+int msgget(key_t key, int msgflg) -+{ -+ return syscall(__NR_msgget, key, msgflg); -+} -+ -+int semget(key_t key, int nsems, int semflg) -+{ -+ return syscall(__NR_semget, key, nsems, semflg); -+} -+ - # if __ANDROID_API__ < 21 - int tcdrain(int fd) - { --- -2.45.2 - diff --git a/patches/0009-Use-bionic-libresolv-for-nslookup.patch b/patches/0009-Use-bionic-libresolv-for-nslookup.patch new file mode 100644 index 0000000..d3818dc --- /dev/null +++ b/patches/0009-Use-bionic-libresolv-for-nslookup.patch @@ -0,0 +1,203 @@ +From 2eb6acaf13508003e26d51cbce7bc42b49634e3c Mon Sep 17 00:00:00 2001 +From: topjohnwu +Date: Mon, 15 Jul 2024 17:20:17 -0700 +Subject: [PATCH 09/17] Use bionic libresolv for nslookup + +--- + networking/bionic_resolv.h | 112 +++++++++++++++++++++++++++++++++++++ + networking/nslookup.c | 27 ++++----- + 2 files changed, 124 insertions(+), 15 deletions(-) + create mode 100644 networking/bionic_resolv.h + +diff --git a/networking/bionic_resolv.h b/networking/bionic_resolv.h +new file mode 100644 +index 000000000..a15cb587b +--- /dev/null ++++ b/networking/bionic_resolv.h +@@ -0,0 +1,112 @@ ++#pragma once ++ ++// Struct/function definitions copied from headers in bionic/libc/dns ++ ++#include ++#include ++ ++/* Hard-coded defines */ ++#define MAXNS 4 /* max # name servers we'll track */ ++#define MAXDNSRCH 6 /* max # domains in search path */ ++#define MAXDNSRCHPATH 256 /* max length of domain search paths */ ++#define MAXNSSAMPLES 64 /* max # samples to store per server */ ++#define MAXRESOLVSORT 10 /* number of net to sort on */ ++#define MAXALIASES 35 ++#define MAXADDRS 35 ++ ++// These are function pointers ++typedef void* res_send_rhook; ++typedef void* res_send_qhook; ++ ++struct res_static { ++ char* h_addr_ptrs[MAXADDRS + 1]; ++ char* host_aliases[MAXALIASES]; ++ char hostbuf[8 * 1024]; ++ u_int32_t host_addr[16 / sizeof(u_int32_t)]; /* IPv4 or IPv6 */ ++ FILE* hostf; ++ int stayopen; ++ const char* servent_ptr; ++ struct servent servent; ++ struct hostent host; ++}; ++ ++union res_sockaddr_union { ++ struct sockaddr_in sin; ++#ifdef IN6ADDR_ANY_INIT ++ struct sockaddr_in6 sin6; ++#endif ++#ifdef ISC_ALIGN64 ++ int64_t __align64; /* 64bit alignment */ ++#else ++ int32_t __align32; /* 32bit alignment */ ++#endif ++ char __space[128]; /* max size */ ++}; ++ ++struct __res_state_ext { ++ union res_sockaddr_union nsaddrs[MAXNS]; ++ struct sort_list { ++ int af; ++ union { ++ struct in_addr ina; ++ struct in6_addr in6a; ++ } addr, mask; ++ } sort_list[MAXRESOLVSORT]; ++ char nsuffix[64]; ++ char nsuffix2[64]; ++}; ++ ++struct __res_state { ++ unsigned netid; /* NetId: cache key and socket mark */ ++ int retrans; /* retransmission time interval */ ++ int retry; /* number of times to retransmit */ ++#ifdef sun ++ u_int options; /* option flags - see below. */ ++#else ++ u_long options; /* option flags - see below. */ ++#endif ++ int nscount; /* number of name servers */ ++ struct sockaddr_in ++ nsaddr_list[MAXNS]; /* address of name server */ ++#define nsaddr nsaddr_list[0] /* for backward compatibility */ ++ u_short id; /* current message id */ ++ char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */ ++ char defdname[256]; /* default domain (deprecated) */ ++#ifdef sun ++ u_int pfcode; /* RES_PRF_ flags - see below. */ ++#else ++ u_long pfcode; /* RES_PRF_ flags - see below. */ ++#endif ++ unsigned ndots:4; /* threshold for initial abs. query */ ++ unsigned nsort:4; /* number of elements in sort_list[] */ ++ char unused[3]; ++ struct { ++ struct in_addr addr; ++ uint32_t mask; ++ } sort_list[MAXRESOLVSORT]; ++#ifdef __OLD_RES_STATE ++ char lookups[4]; ++#else ++ res_send_qhook qhook; /* query hook */ ++ res_send_rhook rhook; /* response hook */ ++ int res_h_errno; /* last one set for this context */ ++ unsigned _mark; /* If non-0 SET_MARK to _mark on all request sockets */ ++ int _vcsock; /* PRIVATE: for res_send VC i/o */ ++ u_int _flags; /* PRIVATE: see below */ ++ u_int _pad; /* make _u 64 bit aligned */ ++ union { ++ /* On an 32-bit arch this means 512b total. */ ++ char pad[72 - 4*sizeof (int) - 2*sizeof (void *)]; ++ struct { ++ uint16_t nscount; ++ uint16_t nstimes[MAXNS]; /* ms. */ ++ int nssocks[MAXNS]; ++ struct __res_state_ext *ext; /* extention for IPv6 */ ++ } _ext; ++ } _u; ++#endif ++ struct res_static rstatic[1]; ++}; ++ ++extern struct __res_state *__res_get_state(void); ++#define _res (*__res_get_state()) +diff --git a/networking/nslookup.c b/networking/nslookup.c +index 6da97baf4..0441ab116 100644 +--- a/networking/nslookup.c ++++ b/networking/nslookup.c +@@ -40,6 +40,9 @@ + //#include + #include "libbb.h" + #include "common_bufsiz.h" ++#ifdef __BIONIC__ ++#include "bionic_resolv.h" ++#endif + + + #if !ENABLE_FEATURE_NSLOOKUP_BIG +@@ -148,7 +151,8 @@ static void server_print(void) + struct sockaddr *sa; + + #if ENABLE_FEATURE_IPV6 +- sa = (struct sockaddr*)_res._u._ext.nsaddrs[0]; ++ if (_res._u._ext.nscount) ++ sa = (struct sockaddr*)&_res._u._ext.ext->nsaddrs[0].sin6; + if (!sa) + #endif + sa = (struct sockaddr*)&_res.nsaddr_list[0]; +@@ -166,8 +170,9 @@ static void set_default_dns(const char *server) + { + len_and_sockaddr *lsa; + ++ // Set a fallback DNS server + if (!server) +- return; ++ server = "8.8.8.8"; + + /* NB: this works even with, say, "[::1]:5353"! :) */ + lsa = xhost2sockaddr(server, 53); +@@ -178,20 +183,15 @@ static void set_default_dns(const char *server) + _res.nsaddr_list[0] = lsa->u.sin; + } + #if ENABLE_FEATURE_IPV6 +- /* Hoped libc can cope with IPv4 address there too. +- * No such luck, glibc 2.4 segfaults even with IPv6, +- * maybe I misunderstand how to make glibc use IPv6 addr? +- * (uclibc 0.9.31+ should work) */ + if (lsa->u.sa.sa_family == AF_INET6) { +- // glibc neither SEGVs nor sends any dgrams with this +- // (strace shows no socket ops): +- //_res.nscount = 0; ++ _res.nscount = 1; + _res._u._ext.nscount = 1; +- /* store a pointer to part of malloc'ed lsa */ +- _res._u._ext.nsaddrs[0] = &lsa->u.sin6; +- /* must not free(lsa)! */ ++ /* struct copy */ ++ _res._u._ext.ext->nsaddrs[0].sin6 = lsa->u.sin6; ++ _res.nsaddr_list[0].sin_family = 0; + } + #endif ++ free(lsa); + } + + int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +@@ -205,9 +205,6 @@ int nslookup_main(int argc, char **argv) + if (!argv[1] || argv[1][0] == '-' || argc > 3) + bb_show_usage(); + +- /* initialize DNS structure _res used in printing the default +- * name server and in the explicit name server option feature. */ +- res_init(); + /* rfc2133 says this enables IPv6 lookups */ + /* (but it also says "may be enabled in /etc/resolv.conf") */ + /*_res.options |= RES_USE_INET6;*/ +-- +2.45.2 + diff --git a/patches/0009-android-syscalls-msgctl-shmctl.patch b/patches/0009-android-syscalls-msgctl-shmctl.patch deleted file mode 100644 index 192a4a0..0000000 --- a/patches/0009-android-syscalls-msgctl-shmctl.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 8ba5becb43f65b01c1f4c3c858ea5557fadf057a Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Mon, 12 Sep 2016 14:46:40 -0300 -Subject: [PATCH 09/35] android syscalls: msgctl shmctl - -Patch by Tias Guns -Rebased for busybox 1.25.0 by Chris Renshaw ---- - libbb/missing_syscalls.c | 13 +++++++++++++ - 1 file changed, 13 insertions(+) - -diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c -index 82b600ced..018f72d62 100644 ---- a/libbb/missing_syscalls.c -+++ b/libbb/missing_syscalls.c -@@ -46,6 +46,19 @@ int semget(key_t key, int nsems, int semflg) - return syscall(__NR_semget, key, nsems, semflg); - } - -+struct msqid_ds; /* #include */ -+int msgctl(int msqid, int cmd, struct msqid_ds *buf) -+{ -+ return syscall(__NR_msgctl, msqid, cmd, buf); -+} -+ -+struct shmid_ds; /* #include */ -+// NOTE: IPC_INFO takes a struct shminfo64 -+int shmctl(int shmid, int cmd, struct shmid_ds *buf) -+{ -+ return syscall(__NR_shmctl, shmid, cmd, buf); -+} -+ - # if __ANDROID_API__ < 21 - int tcdrain(int fd) - { --- -2.45.2 - diff --git a/patches/0002-Fix-direct-mount-.img-auto-loopback-and-losetup-for-.patch b/patches/0010-Fix-direct-mount-auto-loopback-and-losetup-for-Andro.patch similarity index 85% rename from patches/0002-Fix-direct-mount-.img-auto-loopback-and-losetup-for-.patch rename to patches/0010-Fix-direct-mount-auto-loopback-and-losetup-for-Andro.patch index 543e70e..15635a3 100644 --- a/patches/0002-Fix-direct-mount-.img-auto-loopback-and-losetup-for-.patch +++ b/patches/0010-Fix-direct-mount-auto-loopback-and-losetup-for-Andro.patch @@ -1,8 +1,7 @@ -From a84db18ef75d4d5afe8ff1090297bd9329b75c3a Mon Sep 17 00:00:00 2001 +From 9cb8d202d99a8126413283d50dbe83e457387689 Mon Sep 17 00:00:00 2001 From: Chris Renshaw Date: Wed, 24 May 2023 14:15:00 -0300 -Subject: [PATCH 02/35] Fix direct mount .img (auto loopback) and losetup for - Android /dev/block/loop +Subject: [PATCH 10/17] Fix direct mount auto loopback and losetup for Android --- include/libbb.h | 12 +++++++++--- diff --git a/patches/0010-android-syscalls-shmdt-shmat-sembuf.patch b/patches/0010-android-syscalls-shmdt-shmat-sembuf.patch deleted file mode 100644 index 0d88c46..0000000 --- a/patches/0010-android-syscalls-shmdt-shmat-sembuf.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 8f4de5081b22de50f52a70fc79d9696646914fb9 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Mon, 12 Sep 2016 14:48:30 -0300 -Subject: [PATCH 10/35] android syscalls: shmdt shmat sembuf - -Patch by Tias Guns -Rebased for busybox 1.25.0 by Chris Renshaw ---- - libbb/missing_syscalls.c | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) - -diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c -index 018f72d62..b5ea2612e 100644 ---- a/libbb/missing_syscalls.c -+++ b/libbb/missing_syscalls.c -@@ -36,6 +36,16 @@ int shmget(key_t key, size_t size, int shmflg) - return syscall(__NR_shmget, key, size, shmflg); - } - -+int shmdt(const void *shmaddr) -+{ -+ return syscall(__NR_shmdt, shmaddr); -+} -+ -+void *shmat(int shmid, const void *shmaddr, int shmflg) -+{ -+ return (void *)syscall(__NR_shmat, shmid, shmaddr, shmflg); -+} -+ - int msgget(key_t key, int msgflg) - { - return syscall(__NR_msgget, key, msgflg); -@@ -59,6 +69,12 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf) - return syscall(__NR_shmctl, shmid, cmd, buf); - } - -+struct sembuf; /* #include */ -+int semop(int semid, struct sembuf *sops, unsigned nsops) -+{ -+ return syscall(__NR_semop, semid, sops, nsops); -+} -+ - # if __ANDROID_API__ < 21 - int tcdrain(int fd) - { --- -2.45.2 - diff --git a/patches/0027-ash-history.patch b/patches/0011-Update-shell-paths-to-Android-specific-values.patch similarity index 70% rename from patches/0027-ash-history.patch rename to patches/0011-Update-shell-paths-to-Android-specific-values.patch index d480ed8..3f39471 100644 --- a/patches/0027-ash-history.patch +++ b/patches/0011-Update-shell-paths-to-Android-specific-values.patch @@ -1,19 +1,14 @@ -From 4e1b8164fb241cba15f4a41871d44f1aecfa2c26 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Tue, 23 May 2023 18:30:43 -0300 -Subject: [PATCH 27/35] ash history +From 7d82ae116d7c3a3aa6d9048574fdf0564d513378 Mon Sep 17 00:00:00 2001 +From: topjohnwu +Date: Mon, 15 Jul 2024 17:44:50 -0700 +Subject: [PATCH 11/17] Update shell paths to Android specific values -allows ash history to work on Android - -Patch modified by Tias Guns from 'busybox-android.patch' by Alexandre Courbot -https://github.com/Gnurou/busybox-android -Rebased for busybox 1.36.1 by Chris Renshaw --- include/libbb.h | 4 ++-- init/init.c | 2 +- libbb/get_shell_name.c | 4 ++++ - shell/ash.c | 8 ++++++-- - 4 files changed, 13 insertions(+), 5 deletions(-) + shell/ash.c | 4 ++-- + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 87dd74e48..112e45197 100644 @@ -63,7 +58,7 @@ index 5aebe9cdc..5af53bdda 100644 if (pw && pw->pw_shell && pw->pw_shell[0]) return pw->pw_shell; diff --git a/shell/ash.c b/shell/ash.c -index 9344e4de1..5dd7f80f1 100644 +index 9344e4de1..19eed5451 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -14537,7 +14537,7 @@ procargs(char **argv) @@ -84,24 +79,6 @@ index 9344e4de1..5dd7f80f1 100644 state1: state = 2; hp = lookupvar("HOME"); -@@ -14758,6 +14758,9 @@ int ash_main(int argc UNUSED_PARAM, char **argv) - if (line_input_state) { - const char *hp = lookupvar("HISTFILE"); - if (!hp) { -+#ifdef __ANDROID__ -+ setvar("HISTFILE", "/mnt/sdcard/ash_history", 0); -+#else - hp = lookupvar("HOME"); - if (hp) { - INT_OFF; -@@ -14767,6 +14770,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) - INT_ON; - hp = lookupvar("HISTFILE"); - } -+#endif - } - if (hp) - line_input_state->hist_file = xstrdup(hp); -- 2.45.2 diff --git a/patches/0011-android-syscall-non-trivial-semctl.patch b/patches/0011-android-syscall-non-trivial-semctl.patch deleted file mode 100644 index fd5f817..0000000 --- a/patches/0011-android-syscall-non-trivial-semctl.patch +++ /dev/null @@ -1,84 +0,0 @@ -From f8f14deeffacdb3d3e4df817b87ccb260e6b4c38 Mon Sep 17 00:00:00 2001 -From: Tias Guns -Date: Sun, 5 Aug 2012 15:25:34 +0200 -Subject: [PATCH 11/35] android syscall (non-trivial): semctl - -needed by ipcs and ipcrm, also needed (but not sufficient) for syslogd and logread - -semctl from glibc -patch from 'no-sys-shm,msg,sem' by Dan Drown -http://dan.drown.org/android/src/busybox/ - -Signed-off-by: Tias Guns ---- - libbb/semctl.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 58 insertions(+) - create mode 100644 libbb/semctl.c - -diff --git a/libbb/semctl.c b/libbb/semctl.c -new file mode 100644 -index 000000000..2c600e4f0 ---- /dev/null -+++ b/libbb/semctl.c -@@ -0,0 +1,58 @@ -+/* Copyright (C) 1995,1997,1998,2000,2003,2004,2006 -+ Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ Contributed by Ulrich Drepper , August 1995. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, write to the Free -+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -+ 02111-1307 USA. */ -+/* originally from glibc-2.14/sysdeps/unix/sysv/linux/semctl.c, modified */ -+ -+// syscall used by syslogd, ipcrm, ipcs -+//kbuild:lib-y += semctl.o -+ -+#include /* For __NR_xxx definitions */ -+#include -+#include -+#include "libbb.h" -+ -+/* code from GLIBC */ -+int semctl(int semid, int semnum, int cmd, ...) { -+ union semun arg; -+ va_list ap; -+ -+ va_start (ap, cmd); -+ -+ /* Get the argument only if required. */ -+ arg.buf = NULL; -+ switch (cmd) -+ { -+ case SETVAL: /* arg.val */ -+ case GETALL: /* arg.array */ -+ case SETALL: -+ case IPC_STAT: /* arg.buf */ -+ case IPC_SET: -+ case SEM_STAT: -+ case IPC_INFO: /* arg.__buf */ -+ case SEM_INFO: -+ va_start (ap, cmd); -+ arg = va_arg (ap, union semun); -+ va_end (ap); -+ break; -+ } -+ -+ va_end (ap); -+ -+ return syscall(__NR_semctl, semid, semnum, cmd, arg); -+} --- -2.45.2 - diff --git a/patches/0033-Disable-SELinux-features-for-install.patch b/patches/0012-Disable-SELinux-features-for-install.patch similarity index 87% rename from patches/0033-Disable-SELinux-features-for-install.patch rename to patches/0012-Disable-SELinux-features-for-install.patch index 0ffc444..904f293 100644 --- a/patches/0033-Disable-SELinux-features-for-install.patch +++ b/patches/0012-Disable-SELinux-features-for-install.patch @@ -1,7 +1,7 @@ -From 6de85bca13186f6056c78afe264cad7efa5f8eb3 Mon Sep 17 00:00:00 2001 +From 4732054018b9f22edeb2b47153352a1399c5bc5a Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 2 May 2020 01:48:30 -0700 -Subject: [PATCH 33/35] Disable SELinux features for install +Subject: [PATCH 12/17] Disable SELinux features for install matchpathcon is not usable on Android --- diff --git a/patches/0012-missing_syscalls-semctl-fix-missing-definitions-on-x.patch b/patches/0012-missing_syscalls-semctl-fix-missing-definitions-on-x.patch deleted file mode 100644 index b44a63a..0000000 --- a/patches/0012-missing_syscalls-semctl-fix-missing-definitions-on-x.patch +++ /dev/null @@ -1,85 +0,0 @@ -From 24a899b5756eb827998ce2aaf589933128998439 Mon Sep 17 00:00:00 2001 -From: Umakanthan Chandran -Date: Fri, 3 Mar 2017 07:32:22 +0530 -Subject: [PATCH 12/35] missing_syscalls/semctl: fix missing definitions on x86 - and MIPS NDK cross-compiles - -Signed-off-by: Umakanthan Chandran ---- - libbb/missing_syscalls.c | 44 ++++++++++++++++++++++++++++++++++++++++ - libbb/semctl.c | 4 ++++ - 2 files changed, 48 insertions(+) - -diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c -index b5ea2612e..f02e8d14c 100644 ---- a/libbb/missing_syscalls.c -+++ b/libbb/missing_syscalls.c -@@ -7,6 +7,50 @@ - - #include "libbb.h" - -+#ifndef __NR_shmget -+#define __NR_shmget 29 -+#endif -+ -+#ifndef __NR_shmat -+#define __NR_shmat 30 -+#endif -+ -+#ifndef __NR_shmctl -+#define __NR_shmctl 31 -+#endif -+ -+#ifndef __NR_semget -+#define __NR_semget 64 -+#endif -+ -+#ifndef __NR_semop -+#define __NR_semop 65 -+#endif -+ -+#ifndef __NR_semctl -+#define __NR_semctl 66 -+#endif -+ -+#ifndef __NR_shmdt -+#define __NR_shmdt 67 -+#endif -+ -+#ifndef __NR_msgget -+#define __NR_msgget 68 -+#endif -+ -+#ifndef __NR_msgsnd -+#define __NR_msgsnd 69 -+#endif -+ -+#ifndef __NR_msgrcv -+#define __NR_msgrcv 70 -+#endif -+ -+#ifndef __NR_msgctl -+#define __NR_msgctl 71 -+#endif -+ - #if defined(ANDROID) || defined(__ANDROID__) - /*# include - for struct timex, but may collide with */ - # include -diff --git a/libbb/semctl.c b/libbb/semctl.c -index 2c600e4f0..84ab1c92e 100644 ---- a/libbb/semctl.c -+++ b/libbb/semctl.c -@@ -27,6 +27,10 @@ - #include - #include "libbb.h" - -+#ifndef __NR_semctl -+#define __NR_semctl 66 -+#endif -+ - /* code from GLIBC */ - int semctl(int semid, int semnum, int cmd, ...) { - union semun arg; --- -2.45.2 - diff --git a/patches/0028-Replace-realpath-to-BSD-inplementation.patch b/patches/0013-Replace-realpath-to-BSD-inplementation.patch similarity index 95% rename from patches/0028-Replace-realpath-to-BSD-inplementation.patch rename to patches/0013-Replace-realpath-to-BSD-inplementation.patch index f85a4b0..bd566fa 100644 --- a/patches/0028-Replace-realpath-to-BSD-inplementation.patch +++ b/patches/0013-Replace-realpath-to-BSD-inplementation.patch @@ -1,26 +1,28 @@ -From e58c3ad5272ccb534848d33cbd02a38d6b4d523b Mon Sep 17 00:00:00 2001 +From 919bf6bfbe8b8a26ad3fc80d53aa5f2221aff1ed Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 20 Mar 2022 00:51:25 +0800 -Subject: [PATCH 28/35] Replace `realpath` to BSD inplementation +Subject: [PATCH 13/17] Replace `realpath` to BSD inplementation --- - libbb/Kbuild.src | 1 + + libbb/Kbuild.src | 3 + libbb/wrap_funcs.c | 221 +++++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 222 insertions(+) + 2 files changed, 224 insertions(+) create mode 100644 libbb/wrap_funcs.c diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src -index 33c33b6be..390b1eb10 100644 +index 653025e56..4ac314bdb 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src -@@ -120,6 +120,7 @@ lib-y += xrealloc_vector.o +@@ -118,6 +118,9 @@ lib-y += xgethostbyname.o + lib-y += xreadlink.o + lib-y += xrealloc_vector.o - # for android-busybox-ndk - lib-y += mntent_r.o ++# for android-busybox-ndk +lib-y += wrap_funcs.o - ++ lib-$(CONFIG_MOUNT) += match_fstype.o lib-$(CONFIG_UMOUNT) += match_fstype.o + diff --git a/libbb/wrap_funcs.c b/libbb/wrap_funcs.c new file mode 100644 index 000000000..d4548859a diff --git a/patches/0029-Replace-rename-2-with-direct-system-call.patch b/patches/0014-Replace-rename-2-with-direct-system-call.patch similarity index 92% rename from patches/0029-Replace-rename-2-with-direct-system-call.patch rename to patches/0014-Replace-rename-2-with-direct-system-call.patch index 7bc48f2..9153279 100644 --- a/patches/0029-Replace-rename-2-with-direct-system-call.patch +++ b/patches/0014-Replace-rename-2-with-direct-system-call.patch @@ -1,7 +1,7 @@ -From 00fa13d7d9acfe4f99968ccfd8f6f43cfd49ad3a Mon Sep 17 00:00:00 2001 +From 8c3bb497fbc8b780c8f6b163882f9b3e636b84ae Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 2 Sep 2023 05:21:13 -0700 -Subject: [PATCH 29/35] Replace rename(2) with direct system call +Subject: [PATCH 14/17] Replace rename(2) with direct system call NDK r26 introduced the following change: https://android-review.googlesource.com/c/platform/bionic/+/2240019 diff --git a/patches/0014-fix-fsck.minix-mkfs.minix-undef-HAVE_SETBIT-MINIX2_S.patch b/patches/0014-fix-fsck.minix-mkfs.minix-undef-HAVE_SETBIT-MINIX2_S.patch deleted file mode 100644 index 2386a1b..0000000 --- a/patches/0014-fix-fsck.minix-mkfs.minix-undef-HAVE_SETBIT-MINIX2_S.patch +++ /dev/null @@ -1,47 +0,0 @@ -From d4d38041c251f53f728473d4f8f4720a5c85dc9c Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Sun, 18 Feb 2018 07:54:58 -0400 -Subject: [PATCH 14/35] fix fsck.minix, mkfs.minix: undef HAVE_SETBIT, - MINIX2_SUPER_MAGIC, MINIX2_SUPER_MAGIC - -"there is no setbit/clrbit in bionic" -"MINIX2_SUPER_MAGIC / MINIX2_SUPER_MAGIC2 defined in sys/vfs.h, undefine -it to use it in the enum" - -Patch by Tias Guns , based on 'no-setbit' and -'undefine-minix2-magic-to-use-in-enum' by Dan Drown -http://dan.drown.org/android/src/busybox/ -Rebased for busybox 1.28.1 by Chris Renshaw ---- - include/platform.h | 1 + - util-linux/minix.h | 2 ++ - 2 files changed, 3 insertions(+) - -diff --git a/include/platform.h b/include/platform.h -index ea0512f36..6644d83c6 100644 ---- a/include/platform.h -+++ b/include/platform.h -@@ -551,6 +551,7 @@ typedef unsigned smalluint; - # undef HAVE_UNLOCKED_LINE_OPS - # undef HAVE_NET_ETHERNET_H - # undef HAVE_PRINTF_PERCENTM -+# undef HAVE_SETBIT - #endif - - /* -diff --git a/util-linux/minix.h b/util-linux/minix.h -index 83ffe6da5..91ced691c 100644 ---- a/util-linux/minix.h -+++ b/util-linux/minix.h -@@ -54,6 +54,8 @@ struct minix_dir_entry { - /* Believe it or not, but mount.h has this one #defined */ - #undef BLOCK_SIZE - -+#undef MINIX2_SUPER_MAGIC -+#undef MINIX2_SUPER_MAGIC2 - enum { - BLOCK_SIZE = 1024, - BITS_PER_BLOCK = BLOCK_SIZE << 3, --- -2.45.2 - diff --git a/patches/0031-Add-runtime-toggle-to-enable-standalone-ash.patch b/patches/0015-Add-runtime-toggle-to-enable-standalone-ash.patch similarity index 95% rename from patches/0031-Add-runtime-toggle-to-enable-standalone-ash.patch rename to patches/0015-Add-runtime-toggle-to-enable-standalone-ash.patch index 57f58fc..20cf649 100644 --- a/patches/0031-Add-runtime-toggle-to-enable-standalone-ash.patch +++ b/patches/0015-Add-runtime-toggle-to-enable-standalone-ash.patch @@ -1,14 +1,14 @@ -From c7e6de2748301c1420e8b39d1e438874e52da4ff Mon Sep 17 00:00:00 2001 +From 0cc05e531c03124e9611f411b97fb32b90a8d229 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 7 Feb 2020 14:32:06 -0800 -Subject: [PATCH 31/35] Add runtime toggle to enable standalone ash +Subject: [PATCH 15/17] Add runtime toggle to enable standalone ash --- shell/ash.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/shell/ash.c b/shell/ash.c -index 5dd7f80f1..9ab1cb327 100644 +index 19eed5451..34a540049 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -279,16 +279,14 @@ typedef long arith_t; diff --git a/patches/0015-fix-ipv6-add-ipv6_route.h.patch b/patches/0015-fix-ipv6-add-ipv6_route.h.patch deleted file mode 100644 index fd32210..0000000 --- a/patches/0015-fix-ipv6-add-ipv6_route.h.patch +++ /dev/null @@ -1,114 +0,0 @@ -From e0565bde5f6246304751ae2d9f9f3a37c31d551a Mon Sep 17 00:00:00 2001 -From: Tias Guns -Date: Mon, 19 Mar 2012 18:24:29 +0000 -Subject: [PATCH 15/35] fix ipv6, add ipv6_route.h - -from 'in6_rtmsg' by Dan Drown -"in6_rtmsg defined in linux/ipv6_route.h" -http://dan.drown.org/android/src/busybox/ ---- - include/linux/ipv6_route.h | 58 ++++++++++++++++++++++++++++++++++++++ - networking/ifconfig.c | 2 ++ - networking/route.c | 2 ++ - 3 files changed, 62 insertions(+) - create mode 100644 include/linux/ipv6_route.h - -diff --git a/include/linux/ipv6_route.h b/include/linux/ipv6_route.h -new file mode 100644 -index 000000000..144875dab ---- /dev/null -+++ b/include/linux/ipv6_route.h -@@ -0,0 +1,58 @@ -+/* -+ * Linux INET6 implementation -+ * -+ * Authors: -+ * Pedro Roque -+ * -+ * This program is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU General Public License -+ * as published by the Free Software Foundation; either version -+ * 2 of the License, or (at your option) any later version. -+ */ -+ -+#ifndef _LINUX_IPV6_ROUTE_H -+#define _LINUX_IPV6_ROUTE_H -+ -+#include -+ -+#define RTF_DEFAULT 0x00010000 /* default - learned via ND */ -+#define RTF_ALLONLINK 0x00020000 /* (deprecated and will be removed) -+ fallback, no routers on link */ -+#define RTF_ADDRCONF 0x00040000 /* addrconf route - RA */ -+#define RTF_PREFIX_RT 0x00080000 /* A prefix only route - RA */ -+#define RTF_ANYCAST 0x00100000 /* Anycast */ -+ -+#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */ -+#define RTF_EXPIRES 0x00400000 -+ -+#define RTF_ROUTEINFO 0x00800000 /* route information - RA */ -+ -+#define RTF_CACHE 0x01000000 /* cache entry */ -+#define RTF_FLOW 0x02000000 /* flow significant route */ -+#define RTF_POLICY 0x04000000 /* policy route */ -+ -+#define RTF_PREF(pref) ((pref) << 27) -+#define RTF_PREF_MASK 0x18000000 -+ -+#define RTF_LOCAL 0x80000000 -+ -+ -+struct in6_rtmsg { -+ struct in6_addr rtmsg_dst; -+ struct in6_addr rtmsg_src; -+ struct in6_addr rtmsg_gateway; -+ __u32 rtmsg_type; -+ __u16 rtmsg_dst_len; -+ __u16 rtmsg_src_len; -+ __u32 rtmsg_metric; -+ unsigned long rtmsg_info; -+ __u32 rtmsg_flags; -+ int rtmsg_ifindex; -+}; -+ -+#define RTMSG_NEWDEVICE 0x11 -+#define RTMSG_DELDEVICE 0x12 -+#define RTMSG_NEWROUTE 0x21 -+#define RTMSG_DELROUTE 0x22 -+ -+#endif -diff --git a/networking/ifconfig.c b/networking/ifconfig.c -index 9ee232a66..f9a66e801 100644 ---- a/networking/ifconfig.c -+++ b/networking/ifconfig.c -@@ -128,12 +128,14 @@ - #endif - - #if ENABLE_FEATURE_IPV6 -+#ifndef __BIONIC__ - struct in6_ifreq { - struct in6_addr ifr6_addr; - uint32_t ifr6_prefixlen; - int ifr6_ifindex; - }; - #endif -+#endif - - /* - * Here are the bit masks for the "flags" member of struct options below. -diff --git a/networking/route.c b/networking/route.c -index 26146f8e9..7b5be0e73 100644 ---- a/networking/route.c -+++ b/networking/route.c -@@ -36,6 +36,8 @@ - - #include - #include -+#include -+#include - - #include "libbb.h" - #include "inet_common.h" --- -2.45.2 - diff --git a/patches/0032-Resolve-proc-self-exe-when-re-exec-ourselves.patch b/patches/0016-Resolve-proc-self-exe-when-re-exec-ourselves.patch similarity index 93% rename from patches/0032-Resolve-proc-self-exe-when-re-exec-ourselves.patch rename to patches/0016-Resolve-proc-self-exe-when-re-exec-ourselves.patch index e037d14..5e17415 100644 --- a/patches/0032-Resolve-proc-self-exe-when-re-exec-ourselves.patch +++ b/patches/0016-Resolve-proc-self-exe-when-re-exec-ourselves.patch @@ -1,7 +1,7 @@ -From 4e6f42c344f6c0af35037cf78bc9431e64e0bad7 Mon Sep 17 00:00:00 2001 +From 9e08908e035682a76ca93410bbd651a0407cddc4 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 25 Jun 2020 03:54:53 -0700 -Subject: [PATCH 32/35] Resolve /proc/self/exe when re-exec ourselves +Subject: [PATCH 16/17] Resolve /proc/self/exe when re-exec ourselves Use resolved path of /proc/self/exe to workaround Samsung kernel blocking executables running as UID=0 in paths such as /proc. @@ -10,7 +10,7 @@ blocking executables running as UID=0 in paths such as /proc. 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/shell/ash.c b/shell/ash.c -index 9ab1cb327..11c9cb4cc 100644 +index 34a540049..4dae9a474 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -8252,6 +8252,7 @@ static struct tblentry **cmdtable; diff --git a/patches/0016-additional-fix-up-for-IPV6-on-Android-API-21.patch b/patches/0016-additional-fix-up-for-IPV6-on-Android-API-21.patch deleted file mode 100644 index 945c1b5..0000000 --- a/patches/0016-additional-fix-up-for-IPV6-on-Android-API-21.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 9b7a89681a0320b930ac9bfda99aa7bb1dd7961f Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Thu, 6 May 2021 16:09:06 -0300 -Subject: [PATCH 16/35] additional fix-up for IPV6 on Android API 21+ - -fixes: networking/interface.c:62:8: error: redefinition of 'struct in6_ifreq' - -and: -error: field 'ifru_addr' has incomplete type - struct sockaddr ifru_addr; -error: field 'ifru_dstaddr' has incomplete type - struct sockaddr ifru_dstaddr; -... -since sockaddr was moved from linux/socket.h to sys/socket.h in newer NDK revisions ---- - networking/interface.c | 2 ++ - networking/route.c | 1 + - 2 files changed, 3 insertions(+) - -diff --git a/networking/interface.c b/networking/interface.c -index 6b6c0944a..d5ca48dd9 100644 ---- a/networking/interface.c -+++ b/networking/interface.c -@@ -55,6 +55,7 @@ - - #ifdef HAVE_AFINET6 - # ifndef _LINUX_IN6_H -+# ifndef __BIONIC__ - /* - * This is from linux/include/net/ipv6.h - */ -@@ -63,6 +64,7 @@ struct in6_ifreq { - uint32_t ifr6_prefixlen; - unsigned int ifr6_ifindex; - }; -+# endif - # endif - #endif /* HAVE_AFINET6 */ - -diff --git a/networking/route.c b/networking/route.c -index 7b5be0e73..637433bf8 100644 ---- a/networking/route.c -+++ b/networking/route.c -@@ -36,6 +36,7 @@ - - #include - #include -+#include - #include - #include - --- -2.45.2 - diff --git a/patches/0034-Allow-running-as-libbusybox.so.patch b/patches/0017-Allow-running-as-libbusybox.so.patch similarity index 85% rename from patches/0034-Allow-running-as-libbusybox.so.patch rename to patches/0017-Allow-running-as-libbusybox.so.patch index 65b4f26..868c1ef 100644 --- a/patches/0034-Allow-running-as-libbusybox.so.patch +++ b/patches/0017-Allow-running-as-libbusybox.so.patch @@ -1,7 +1,7 @@ -From 6af96c729231f9266d83e9f06612e150556f1813 Mon Sep 17 00:00:00 2001 +From 0efb2683727f165c1e729db9c2c01a341f038c31 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 21 Jan 2021 00:07:41 -0800 -Subject: [PATCH 34/35] Allow running as libbusybox.so +Subject: [PATCH 17/17] Allow running as libbusybox.so --- libbb/appletlib.c | 5 ++++- diff --git a/patches/0017-fix-udhcpc6-add-missing-ifaddrs.h-and-getifaddrs-fre.patch b/patches/0017-fix-udhcpc6-add-missing-ifaddrs.h-and-getifaddrs-fre.patch deleted file mode 100644 index 7c18555..0000000 --- a/patches/0017-fix-udhcpc6-add-missing-ifaddrs.h-and-getifaddrs-fre.patch +++ /dev/null @@ -1,711 +0,0 @@ -From 5e221150789917928c5c9a67f9fd8a76f9ef5cf6 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Wed, 19 Jul 2017 17:22:55 -0300 -Subject: [PATCH 17/35] fix udhcpc6: add missing ifaddrs.h and - getifaddrs/freeifaddrs functions - -ifaddrs implementation from 'android-ifaddrs' by Kenneth MacKay: -https://github.com/morristech/android-ifaddrs ---- - networking/udhcp/d6_dhcpc.c | 1 + - networking/udhcp/d6_socket.c | 2 +- - networking/udhcp/ifaddrs.c | 600 +++++++++++++++++++++++++++++++++++ - networking/udhcp/ifaddrs.h | 54 ++++ - 4 files changed, 656 insertions(+), 1 deletion(-) - create mode 100644 networking/udhcp/ifaddrs.c - create mode 100644 networking/udhcp/ifaddrs.h - -diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c -index cdd06188e..498ea2690 100644 ---- a/networking/udhcp/d6_dhcpc.c -+++ b/networking/udhcp/d6_dhcpc.c -@@ -48,6 +48,7 @@ - //applet:IF_UDHCPC6(APPLET(udhcpc6, BB_DIR_USR_BIN, BB_SUID_DROP)) - - //kbuild:lib-$(CONFIG_UDHCPC6) += d6_dhcpc.o d6_packet.o d6_socket.o common.o socket.o signalpipe.o -+//kbuild:lib-$(CONFIG_UDHCPC6) += ifaddrs.o - //kbuild:lib-$(CONFIG_FEATURE_UDHCPC6_RFC3646) += domain_codec.o - //kbuild:lib-$(CONFIG_FEATURE_UDHCPC6_RFC4704) += domain_codec.o - -diff --git a/networking/udhcp/d6_socket.c b/networking/udhcp/d6_socket.c -index acf108367..38de5d0d0 100644 ---- a/networking/udhcp/d6_socket.c -+++ b/networking/udhcp/d6_socket.c -@@ -7,7 +7,7 @@ - #include "common.h" - #include "d6_common.h" - #include --#include -+#include "ifaddrs.h" - #include - - int FAST_FUNC d6_read_interface( -diff --git a/networking/udhcp/ifaddrs.c b/networking/udhcp/ifaddrs.c -new file mode 100644 -index 000000000..338fff887 ---- /dev/null -+++ b/networking/udhcp/ifaddrs.c -@@ -0,0 +1,600 @@ -+/* -+Copyright (c) 2013, Kenneth MacKay -+All rights reserved. -+ -+Redistribution and use in source and binary forms, with or without modification, -+are permitted provided that the following conditions are met: -+ * Redistributions of source code must retain the above copyright notice, this -+ list of conditions and the following disclaimer. -+ * Redistributions in binary form must reproduce the above copyright notice, -+ this list of conditions and the following disclaimer in the documentation -+ and/or other materials provided with the distribution. -+ -+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -+*/ -+ -+#include "ifaddrs.h" -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+typedef struct NetlinkList -+{ -+ struct NetlinkList *m_next; -+ struct nlmsghdr *m_data; -+ unsigned int m_size; -+} NetlinkList; -+ -+static int netlink_socket(void) -+{ -+ int l_socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); -+ if(l_socket < 0) -+ { -+ return -1; -+ } -+ -+ struct sockaddr_nl l_addr; -+ memset(&l_addr, 0, sizeof(l_addr)); -+ l_addr.nl_family = AF_NETLINK; -+ if(bind(l_socket, (struct sockaddr *)&l_addr, sizeof(l_addr)) < 0) -+ { -+ close(l_socket); -+ return -1; -+ } -+ -+ return l_socket; -+} -+ -+static int netlink_send(int p_socket, int p_request) -+{ -+ char l_buffer[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + NLMSG_ALIGN(sizeof(struct rtgenmsg))]; -+ memset(l_buffer, 0, sizeof(l_buffer)); -+ struct nlmsghdr *l_hdr = (struct nlmsghdr *)l_buffer; -+ struct rtgenmsg *l_msg = (struct rtgenmsg *)NLMSG_DATA(l_hdr); -+ -+ l_hdr->nlmsg_len = NLMSG_LENGTH(sizeof(*l_msg)); -+ l_hdr->nlmsg_type = p_request; -+ l_hdr->nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; -+ l_hdr->nlmsg_pid = 0; -+ l_hdr->nlmsg_seq = p_socket; -+ l_msg->rtgen_family = AF_UNSPEC; -+ -+ struct sockaddr_nl l_addr; -+ memset(&l_addr, 0, sizeof(l_addr)); -+ l_addr.nl_family = AF_NETLINK; -+ return (sendto(p_socket, l_hdr, l_hdr->nlmsg_len, 0, (struct sockaddr *)&l_addr, sizeof(l_addr))); -+} -+ -+static int netlink_recv(int p_socket, void *p_buffer, size_t p_len) -+{ -+ struct msghdr l_msg; -+ struct iovec l_iov = { p_buffer, p_len }; -+ struct sockaddr_nl l_addr; -+ int l_result; -+ -+ for(;;) -+ { -+ l_msg.msg_name = (void *)&l_addr; -+ l_msg.msg_namelen = sizeof(l_addr); -+ l_msg.msg_iov = &l_iov; -+ l_msg.msg_iovlen = 1; -+ l_msg.msg_control = NULL; -+ l_msg.msg_controllen = 0; -+ l_msg.msg_flags = 0; -+ int l_result = recvmsg(p_socket, &l_msg, 0); -+ -+ if(l_result < 0) -+ { -+ if(errno == EINTR) -+ { -+ continue; -+ } -+ return -2; -+ } -+ -+ if(l_msg.msg_flags & MSG_TRUNC) -+ { // buffer was too small -+ return -1; -+ } -+ return l_result; -+ } -+} -+ -+static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_done) -+{ -+ size_t l_size = 4096; -+ void *l_buffer = NULL; -+ -+ for(;;) -+ { -+ free(l_buffer); -+ l_buffer = malloc(l_size); -+ -+ int l_read = netlink_recv(p_socket, l_buffer, l_size); -+ *p_size = l_read; -+ if(l_read == -2) -+ { -+ free(l_buffer); -+ return NULL; -+ } -+ if(l_read >= 0) -+ { -+ pid_t l_pid = getpid(); -+ struct nlmsghdr *l_hdr; -+ for(l_hdr = (struct nlmsghdr *)l_buffer; NLMSG_OK(l_hdr, (unsigned int)l_read); l_hdr = (struct nlmsghdr *)NLMSG_NEXT(l_hdr, l_read)) -+ { -+ if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket) -+ { -+ continue; -+ } -+ -+ if(l_hdr->nlmsg_type == NLMSG_DONE) -+ { -+ *p_done = 1; -+ break; -+ } -+ -+ if(l_hdr->nlmsg_type == NLMSG_ERROR) -+ { -+ free(l_buffer); -+ return NULL; -+ } -+ } -+ return l_buffer; -+ } -+ -+ l_size *= 2; -+ } -+} -+ -+static NetlinkList *newListItem(struct nlmsghdr *p_data, unsigned int p_size) -+{ -+ NetlinkList *l_item = malloc(sizeof(NetlinkList)); -+ l_item->m_next = NULL; -+ l_item->m_data = p_data; -+ l_item->m_size = p_size; -+ return l_item; -+} -+ -+static void freeResultList(NetlinkList *p_list) -+{ -+ NetlinkList *l_cur; -+ while(p_list) -+ { -+ l_cur = p_list; -+ p_list = p_list->m_next; -+ free(l_cur->m_data); -+ free(l_cur); -+ } -+} -+ -+static NetlinkList *getResultList(int p_socket, int p_request) -+{ -+ if(netlink_send(p_socket, p_request) < 0) -+ { -+ return NULL; -+ } -+ -+ NetlinkList *l_list = NULL; -+ NetlinkList *l_end = NULL; -+ int l_size; -+ int l_done = 0; -+ while(!l_done) -+ { -+ struct nlmsghdr *l_hdr = getNetlinkResponse(p_socket, &l_size, &l_done); -+ if(!l_hdr) -+ { // error -+ freeResultList(l_list); -+ return NULL; -+ } -+ -+ NetlinkList *l_item = newListItem(l_hdr, l_size); -+ if(!l_list) -+ { -+ l_list = l_item; -+ } -+ else -+ { -+ l_end->m_next = l_item; -+ } -+ l_end = l_item; -+ } -+ return l_list; -+} -+ -+static size_t maxSize(size_t a, size_t b) -+{ -+ return (a > b ? a : b); -+} -+ -+static size_t calcAddrLen(sa_family_t p_family, int p_dataSize) -+{ -+ switch(p_family) -+ { -+ case AF_INET: -+ return sizeof(struct sockaddr_in); -+ case AF_INET6: -+ return sizeof(struct sockaddr_in6); -+ case AF_PACKET: -+ return maxSize(sizeof(struct sockaddr_ll), offsetof(struct sockaddr_ll, sll_addr) + p_dataSize); -+ default: -+ return maxSize(sizeof(struct sockaddr), offsetof(struct sockaddr, sa_data) + p_dataSize); -+ } -+} -+ -+static void makeSockaddr(sa_family_t p_family, struct sockaddr *p_dest, void *p_data, size_t p_size) -+{ -+ switch(p_family) -+ { -+ case AF_INET: -+ memcpy(&((struct sockaddr_in*)p_dest)->sin_addr, p_data, p_size); -+ break; -+ case AF_INET6: -+ memcpy(&((struct sockaddr_in6*)p_dest)->sin6_addr, p_data, p_size); -+ break; -+ case AF_PACKET: -+ memcpy(((struct sockaddr_ll*)p_dest)->sll_addr, p_data, p_size); -+ ((struct sockaddr_ll*)p_dest)->sll_halen = p_size; -+ break; -+ default: -+ memcpy(p_dest->sa_data, p_data, p_size); -+ break; -+ } -+ p_dest->sa_family = p_family; -+} -+ -+static void addToEnd(struct ifaddrs **p_resultList, struct ifaddrs *p_entry) -+{ -+ if(!*p_resultList) -+ { -+ *p_resultList = p_entry; -+ } -+ else -+ { -+ struct ifaddrs *l_cur = *p_resultList; -+ while(l_cur->ifa_next) -+ { -+ l_cur = l_cur->ifa_next; -+ } -+ l_cur->ifa_next = p_entry; -+ } -+} -+ -+static void interpretLink(struct nlmsghdr *p_hdr, struct ifaddrs **p_links, struct ifaddrs **p_resultList) -+{ -+ struct ifinfomsg *l_info = (struct ifinfomsg *)NLMSG_DATA(p_hdr); -+ -+ size_t l_nameSize = 0; -+ size_t l_addrSize = 0; -+ size_t l_dataSize = 0; -+ -+ size_t l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifinfomsg)); -+ struct rtattr *l_rta; -+ for(l_rta = (struct rtattr *)(((char *)l_info) + NLMSG_ALIGN(sizeof(struct ifinfomsg))); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) -+ { -+ void *l_rtaData = RTA_DATA(l_rta); -+ size_t l_rtaDataSize = RTA_PAYLOAD(l_rta); -+ switch(l_rta->rta_type) -+ { -+ case IFLA_ADDRESS: -+ case IFLA_BROADCAST: -+ l_addrSize += NLMSG_ALIGN(calcAddrLen(AF_PACKET, l_rtaDataSize)); -+ break; -+ case IFLA_IFNAME: -+ l_nameSize += NLMSG_ALIGN(l_rtaSize + 1); -+ break; -+ case IFLA_STATS: -+ l_dataSize += NLMSG_ALIGN(l_rtaSize); -+ break; -+ default: -+ break; -+ } -+ } -+ -+ struct ifaddrs *l_entry = malloc(sizeof(struct ifaddrs) + l_nameSize + l_addrSize + l_dataSize); -+ memset(l_entry, 0, sizeof(struct ifaddrs)); -+ l_entry->ifa_name = ""; -+ -+ char *l_name = ((char *)l_entry) + sizeof(struct ifaddrs); -+ char *l_addr = l_name + l_nameSize; -+ char *l_data = l_addr + l_addrSize; -+ -+ l_entry->ifa_flags = l_info->ifi_flags; -+ -+ l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifinfomsg)); -+ for(l_rta = (struct rtattr *)(((char *)l_info) + NLMSG_ALIGN(sizeof(struct ifinfomsg))); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) -+ { -+ void *l_rtaData = RTA_DATA(l_rta); -+ size_t l_rtaDataSize = RTA_PAYLOAD(l_rta); -+ switch(l_rta->rta_type) -+ { -+ case IFLA_ADDRESS: -+ case IFLA_BROADCAST: -+ { -+ size_t l_addrLen = calcAddrLen(AF_PACKET, l_rtaDataSize); -+ makeSockaddr(AF_PACKET, (struct sockaddr *)l_addr, l_rtaData, l_rtaDataSize); -+ ((struct sockaddr_ll *)l_addr)->sll_ifindex = l_info->ifi_index; -+ ((struct sockaddr_ll *)l_addr)->sll_hatype = l_info->ifi_type; -+ if(l_rta->rta_type == IFLA_ADDRESS) -+ { -+ l_entry->ifa_addr = (struct sockaddr *)l_addr; -+ } -+ else -+ { -+ l_entry->ifa_broadaddr = (struct sockaddr *)l_addr; -+ } -+ l_addr += NLMSG_ALIGN(l_addrLen); -+ break; -+ } -+ case IFLA_IFNAME: -+ strncpy(l_name, l_rtaData, l_rtaDataSize); -+ l_name[l_rtaDataSize] = '\0'; -+ l_entry->ifa_name = l_name; -+ break; -+ case IFLA_STATS: -+ memcpy(l_data, l_rtaData, l_rtaDataSize); -+ l_entry->ifa_data = l_data; -+ break; -+ default: -+ break; -+ } -+ } -+ -+ addToEnd(p_resultList, l_entry); -+ p_links[l_info->ifi_index - 1] = l_entry; -+} -+ -+static void interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_links, struct ifaddrs **p_resultList) -+{ -+ struct ifaddrmsg *l_info = (struct ifaddrmsg *)NLMSG_DATA(p_hdr); -+ -+ size_t l_nameSize = 0; -+ size_t l_addrSize = 0; -+ -+ int l_addedNetmask = 0; -+ -+ size_t l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg)); -+ struct rtattr *l_rta; -+ for(l_rta = (struct rtattr *)(((char *)l_info) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) -+ { -+ void *l_rtaData = RTA_DATA(l_rta); -+ size_t l_rtaDataSize = RTA_PAYLOAD(l_rta); -+ if(l_info->ifa_family == AF_PACKET) -+ { -+ continue; -+ } -+ -+ switch(l_rta->rta_type) -+ { -+ case IFA_ADDRESS: -+ case IFA_LOCAL: -+ if((l_info->ifa_family == AF_INET || l_info->ifa_family == AF_INET6) && !l_addedNetmask) -+ { // make room for netmask -+ l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize)); -+ l_addedNetmask = 1; -+ } -+ case IFA_BROADCAST: -+ l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize)); -+ break; -+ case IFA_LABEL: -+ l_nameSize += NLMSG_ALIGN(l_rtaSize + 1); -+ break; -+ default: -+ break; -+ } -+ } -+ -+ struct ifaddrs *l_entry = malloc(sizeof(struct ifaddrs) + l_nameSize + l_addrSize); -+ memset(l_entry, 0, sizeof(struct ifaddrs)); -+ l_entry->ifa_name = p_links[l_info->ifa_index - 1]->ifa_name; -+ -+ char *l_name = ((char *)l_entry) + sizeof(struct ifaddrs); -+ char *l_addr = l_name + l_nameSize; -+ -+ l_entry->ifa_flags = l_info->ifa_flags | p_links[l_info->ifa_index - 1]->ifa_flags; -+ -+ l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg)); -+ for(l_rta = (struct rtattr *)(((char *)l_info) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) -+ { -+ void *l_rtaData = RTA_DATA(l_rta); -+ size_t l_rtaDataSize = RTA_PAYLOAD(l_rta); -+ switch(l_rta->rta_type) -+ { -+ case IFA_ADDRESS: -+ case IFA_BROADCAST: -+ case IFA_LOCAL: -+ { -+ size_t l_addrLen = calcAddrLen(l_info->ifa_family, l_rtaDataSize); -+ makeSockaddr(l_info->ifa_family, (struct sockaddr *)l_addr, l_rtaData, l_rtaDataSize); -+ if(l_info->ifa_family == AF_INET6) -+ { -+ if(IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)l_rtaData) || IN6_IS_ADDR_MC_LINKLOCAL((struct in6_addr *)l_rtaData)) -+ { -+ ((struct sockaddr_in6 *)l_addr)->sin6_scope_id = l_info->ifa_index; -+ } -+ } -+ -+ if(l_rta->rta_type == IFA_ADDRESS) -+ { // apparently in a point-to-point network IFA_ADDRESS contains the dest address and IFA_LOCAL contains the local address -+ if(l_entry->ifa_addr) -+ { -+ l_entry->ifa_dstaddr = (struct sockaddr *)l_addr; -+ } -+ else -+ { -+ l_entry->ifa_addr = (struct sockaddr *)l_addr; -+ } -+ } -+ else if(l_rta->rta_type == IFA_LOCAL) -+ { -+ if(l_entry->ifa_addr) -+ { -+ l_entry->ifa_dstaddr = l_entry->ifa_addr; -+ } -+ l_entry->ifa_addr = (struct sockaddr *)l_addr; -+ } -+ else -+ { -+ l_entry->ifa_broadaddr = (struct sockaddr *)l_addr; -+ } -+ l_addr += NLMSG_ALIGN(l_addrLen); -+ break; -+ } -+ case IFA_LABEL: -+ strncpy(l_name, l_rtaData, l_rtaDataSize); -+ l_name[l_rtaDataSize] = '\0'; -+ l_entry->ifa_name = l_name; -+ break; -+ default: -+ break; -+ } -+ } -+ -+ if(l_entry->ifa_addr && (l_entry->ifa_addr->sa_family == AF_INET || l_entry->ifa_addr->sa_family == AF_INET6)) -+ { -+ unsigned l_maxPrefix = (l_entry->ifa_addr->sa_family == AF_INET ? 32 : 128); -+ unsigned l_prefix = (l_info->ifa_prefixlen > l_maxPrefix ? l_maxPrefix : l_info->ifa_prefixlen); -+ char l_mask[16] = {0}; -+ unsigned i; -+ for(i=0; i<(l_prefix/8); ++i) -+ { -+ l_mask[i] = 0xff; -+ } -+ l_mask[i] = 0xff << (8 - (l_prefix % 8)); -+ -+ makeSockaddr(l_entry->ifa_addr->sa_family, (struct sockaddr *)l_addr, l_mask, l_maxPrefix / 8); -+ l_entry->ifa_netmask = (struct sockaddr *)l_addr; -+ } -+ -+ addToEnd(p_resultList, l_entry); -+} -+ -+static void interpret(int p_socket, NetlinkList *p_netlinkList, struct ifaddrs **p_links, struct ifaddrs **p_resultList) -+{ -+ pid_t l_pid = getpid(); -+ for(; p_netlinkList; p_netlinkList = p_netlinkList->m_next) -+ { -+ unsigned int l_nlsize = p_netlinkList->m_size; -+ struct nlmsghdr *l_hdr; -+ for(l_hdr = p_netlinkList->m_data; NLMSG_OK(l_hdr, l_nlsize); l_hdr = NLMSG_NEXT(l_hdr, l_nlsize)) -+ { -+ if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket) -+ { -+ continue; -+ } -+ -+ if(l_hdr->nlmsg_type == NLMSG_DONE) -+ { -+ break; -+ } -+ -+ if(l_hdr->nlmsg_type == RTM_NEWLINK) -+ { -+ interpretLink(l_hdr, p_links, p_resultList); -+ } -+ else if(l_hdr->nlmsg_type == RTM_NEWADDR) -+ { -+ interpretAddr(l_hdr, p_links, p_resultList); -+ } -+ } -+ } -+} -+ -+static unsigned countLinks(int p_socket, NetlinkList *p_netlinkList) -+{ -+ unsigned l_links = 0; -+ pid_t l_pid = getpid(); -+ for(; p_netlinkList; p_netlinkList = p_netlinkList->m_next) -+ { -+ unsigned int l_nlsize = p_netlinkList->m_size; -+ struct nlmsghdr *l_hdr; -+ for(l_hdr = p_netlinkList->m_data; NLMSG_OK(l_hdr, l_nlsize); l_hdr = NLMSG_NEXT(l_hdr, l_nlsize)) -+ { -+ if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket) -+ { -+ continue; -+ } -+ -+ if(l_hdr->nlmsg_type == NLMSG_DONE) -+ { -+ break; -+ } -+ -+ if(l_hdr->nlmsg_type == RTM_NEWLINK) -+ { -+ ++l_links; -+ } -+ } -+ } -+ -+ return l_links; -+} -+ -+int getifaddrs(struct ifaddrs **ifap) -+{ -+ if(!ifap) -+ { -+ return -1; -+ } -+ *ifap = NULL; -+ -+ int l_socket = netlink_socket(); -+ if(l_socket < 0) -+ { -+ return -1; -+ } -+ -+ NetlinkList *l_linkResults = getResultList(l_socket, RTM_GETLINK); -+ if(!l_linkResults) -+ { -+ close(l_socket); -+ return -1; -+ } -+ -+ NetlinkList *l_addrResults = getResultList(l_socket, RTM_GETADDR); -+ if(!l_addrResults) -+ { -+ close(l_socket); -+ freeResultList(l_linkResults); -+ return -1; -+ } -+ -+ unsigned l_numLinks = countLinks(l_socket, l_linkResults) + countLinks(l_socket, l_addrResults); -+ struct ifaddrs *l_links[l_numLinks]; -+ memset(l_links, 0, l_numLinks * sizeof(struct ifaddrs *)); -+ -+ interpret(l_socket, l_linkResults, l_links, ifap); -+ interpret(l_socket, l_addrResults, l_links, ifap); -+ -+ freeResultList(l_linkResults); -+ freeResultList(l_addrResults); -+ close(l_socket); -+ return 0; -+} -+ -+void freeifaddrs(struct ifaddrs *ifa) -+{ -+ struct ifaddrs *l_cur; -+ while(ifa) -+ { -+ l_cur = ifa; -+ ifa = ifa->ifa_next; -+ free(l_cur); -+ } -+} -diff --git a/networking/udhcp/ifaddrs.h b/networking/udhcp/ifaddrs.h -new file mode 100644 -index 000000000..9cd19fec1 ---- /dev/null -+++ b/networking/udhcp/ifaddrs.h -@@ -0,0 +1,54 @@ -+/* -+ * Copyright (c) 1995, 1999 -+ * Berkeley Software Design, Inc. All rights reserved. -+ * -+ * Redistribution and use in source and binary forms, with or without -+ * modification, are permitted provided that the following conditions -+ * are met: -+ * 1. Redistributions of source code must retain the above copyright -+ * notice, this list of conditions and the following disclaimer. -+ * -+ * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND -+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -+ * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE -+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -+ * SUCH DAMAGE. -+ * -+ * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp -+ */ -+ -+#ifndef _IFADDRS_H_ -+#define _IFADDRS_H_ -+ -+struct ifaddrs { -+ struct ifaddrs *ifa_next; -+ char *ifa_name; -+ unsigned int ifa_flags; -+ struct sockaddr *ifa_addr; -+ struct sockaddr *ifa_netmask; -+ struct sockaddr *ifa_dstaddr; -+ void *ifa_data; -+}; -+ -+/* -+ * This may have been defined in . Note that if is -+ * to be included it must be included before this header file. -+ */ -+#ifndef ifa_broadaddr -+#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ -+#endif -+ -+#include -+ -+__BEGIN_DECLS -+extern int getifaddrs(struct ifaddrs **ifap); -+extern void freeifaddrs(struct ifaddrs *ifa); -+__END_DECLS -+ -+#endif --- -2.45.2 - diff --git a/patches/0018-fix-hush-add-missing-definitions-on-Android-API-21.patch b/patches/0018-fix-hush-add-missing-definitions-on-Android-API-21.patch deleted file mode 100644 index 3657df3..0000000 --- a/patches/0018-fix-hush-add-missing-definitions-on-Android-API-21.patch +++ /dev/null @@ -1,74 +0,0 @@ -From 52cb97b856e3f7e6ff9972fc8099170c5574f274 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Sat, 2 Oct 2021 01:11:12 -0300 -Subject: [PATCH 18/35] fix hush: add missing definitions on Android API 21+ - -platform FAST_FUNC adjustment to support NDK unified headers by John Wu - -issetugid is required for hush via glob.c; add the hacky pre-API 21 definition back - -Rebased for busybox 1.34.1 by Chris Renshaw ---- - include/platform.h | 10 +++++++++- - libbb/platform.c | 8 ++++++++ - 2 files changed, 17 insertions(+), 1 deletion(-) - -diff --git a/include/platform.h b/include/platform.h -index 6644d83c6..57f0ef57d 100644 ---- a/include/platform.h -+++ b/include/platform.h -@@ -124,7 +124,7 @@ - * (-DFAST_FUNC= ) - */ - #ifndef FAST_FUNC --# if __GNUC_PREREQ(3,0) && defined(i386) -+# if !defined(__ANDROID__) && __GNUC_PREREQ(3,0) && defined(i386) - /* stdcall makes callee to pop arguments from stack, not caller */ - # define FAST_FUNC __attribute__((regparm(3),stdcall)) - /* #elif ... - add your favorite arch today! */ -@@ -429,6 +429,7 @@ typedef unsigned smalluint; - #define HAVE_SYS_STATFS_H 1 - #define HAVE_PRINTF_PERCENTM 1 - #define HAVE_WAIT3 1 -+#define HAVE_ISSETUGID 1 - #define HAVE_DEV_FD 1 - #define DEV_FD_PREFIX "/dev/fd/" - -@@ -536,6 +537,9 @@ typedef unsigned smalluint; - # else - /* ANDROID >= 21 has standard dprintf */ - # endif -+# if __ANDROID_API__ > 18 -+# undef HAVE_ISSETUGID -+# endif - # if __ANDROID_API__ < 21 - # undef HAVE_TTYNAME_R - # undef HAVE_GETLINE -@@ -636,4 +640,8 @@ extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC - extern ssize_t getline(char **lineptr, size_t *n, FILE *stream) FAST_FUNC; - #endif - -+#ifndef HAVE_ISSETUGID -+extern int issetugid(void) FAST_FUNC; -+#endif -+ - #endif -diff --git a/libbb/platform.c b/libbb/platform.c -index 7913353e2..b652a2112 100644 ---- a/libbb/platform.c -+++ b/libbb/platform.c -@@ -225,3 +225,11 @@ int ttyname_r(int fd, char *buf, size_t buflen) - return 0; - } - #endif -+ -+#ifndef HAVE_ISSETUGID -+int issetugid(void) -+{ -+ /* for Bionic, this is sufficient */ -+ return 0; -+} -+#endif --- -2.45.2 - diff --git a/patches/0019-fix-hush-add-glob-and-sigisemptyset.patch b/patches/0019-fix-hush-add-glob-and-sigisemptyset.patch deleted file mode 100644 index ff8e4fd..0000000 --- a/patches/0019-fix-hush-add-glob-and-sigisemptyset.patch +++ /dev/null @@ -1,967 +0,0 @@ -From 2e11b46a8df4509d8b134f3c0d9df0c626180511 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Tue, 10 Jan 2017 10:49:59 -0400 -Subject: [PATCH 19/35] fix hush, add glob and sigisemptyset - -Patch by Tias Guns , based on 'glob' by Dan Drown -http://dan.drown.org/android/src/busybox/ -Rebased for busybox 1.26.1 by Chris Renshaw ---- - shell/glob.c | 786 ++++++++++++++++++++++++++++++++++++++++++ - shell/glob.h | 113 ++++++ - shell/hush.c | 3 +- - shell/sigisemptyset.c | 8 + - 4 files changed, 909 insertions(+), 1 deletion(-) - create mode 100644 shell/glob.c - create mode 100644 shell/glob.h - create mode 100644 shell/sigisemptyset.c - -diff --git a/shell/glob.c b/shell/glob.c -new file mode 100644 -index 000000000..556d72099 ---- /dev/null -+++ b/shell/glob.c -@@ -0,0 +1,786 @@ -+/* -+ * Modified for the Android NDK by Gabor Cselle, http://www.gaborcselle.com/ -+ * Tested with Android NDK version 5b: http://developer.android.com/sdk/ndk/index.html -+ * Last modified: March 3 2011 -+ * -+ * Copyright (c) 1989, 1993 -+ * The Regents of the University of California. All rights reserved. -+ * -+ * This code is derived from software contributed to Berkeley by -+ * Guido van Rossum. -+ * -+ * Redistribution and use in source and binary forms, with or without -+ * modification, are permitted provided that the following conditions -+ * are met: -+ * 1. Redistributions of source code must retain the above copyright -+ * notice, this list of conditions and the following disclaimer. -+ * 2. Redistributions in binary form must reproduce the above copyright -+ * notice, this list of conditions and the following disclaimer in the -+ * documentation and/or other materials provided with the distribution. -+ * 4. Neither the name of the University nor the names of its contributors -+ * may be used to endorse or promote products derived from this software -+ * without specific prior written permission. -+ * -+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -+ * SUCH DAMAGE. -+ */ -+ -+#if defined(LIBC_SCCS) && !defined(lint) -+static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; -+#endif /* LIBC_SCCS and not lint */ -+#include -+ -+ -+/* -+ * glob(3) -- a superset of the one defined in POSIX 1003.2. -+ * -+ * The [!...] convention to negate a range is supported (SysV, Posix, ksh). -+ * -+ * Optional extra services, controlled by flags not defined by POSIX: -+ * -+ * GLOB_QUOTE: -+ * Escaping convention: \ inhibits any special meaning the following -+ * character might have (except \ at end of string is retained). -+ * GLOB_MAGCHAR: -+ * Set in gl_flags if pattern contained a globbing character. -+ * GLOB_NOMAGIC: -+ * Same as GLOB_NOCHECK, but it will only append pattern if it did -+ * not contain any magic characters. [Used in csh style globbing] -+ * GLOB_ALTDIRFUNC: -+ * Use alternately specified directory access functions. -+ * GLOB_TILDE: -+ * expand ~user/foo to the /home/dir/of/user/foo -+ * GLOB_BRACE: -+ * expand {1,2}{a,b} to 1a 1b 2a 2b -+ * gl_matchc: -+ * Number of matches in the current invocation of glob. -+ */ -+ -+/* -+ * Some notes on multibyte character support: -+ * 1. Patterns with illegal byte sequences match nothing - even if -+ * GLOB_NOCHECK is specified. -+ * 2. Illegal byte sequences in filenames are handled by treating them as -+ * single-byte characters with a value of the first byte of the sequence -+ * cast to wchar_t. -+ * 3. State-dependent encodings are not currently supported. -+ */ -+ -+#include -+#include -+ -+#include -+#include -+#include -+#include "glob.h" -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+//#include "collate.h" - NOTE(gabor): I took this out because it's not available for Android -+// and collate is only used once for string comparisons. As a side-effect, you might not -+// be able to match non-ASCII filenames. -+ -+#define DOLLAR '$' -+#define DOT '.' -+#define EOS '\0' -+#define LBRACKET '[' -+#define NOT '!' -+#define QUESTION '?' -+#define QUOTE '\\' -+#define RANGE '-' -+#define RBRACKET ']' -+#define SEP '/' -+#define STAR '*' -+#define TILDE '~' -+#define UNDERSCORE '_' -+#define LBRACE '{' -+#define RBRACE '}' -+#define SLASH '/' -+#define COMMA ',' -+ -+#define M_PROTECT 0x40 -+#define M_MASK 0xff -+ -+ -+#define M_ALL '*' -+#define M_END ']' -+#define M_NOT '!' -+#define M_ONE '?' -+#define M_RNG '-' -+#define M_SET '[' -+ -+ -+static int g_stat(char *, struct stat *, glob_t *); -+static int g_lstat(char *, struct stat *, glob_t *); -+static DIR *g_opendir(char *, glob_t *); -+static int compare(const void *, const void *); -+static int glob0(const char *, glob_t *, size_t *); -+static int glob1(char *, glob_t *, size_t *); -+static int glob2(char *, char *, char *, char *, glob_t *, size_t *); -+static int glob3(char *, char *, char *, char *, char *, glob_t *, size_t *); -+static int globextend(const char *, glob_t *, size_t *); -+static const char * -+ globtilde(const char *, char *, size_t, glob_t *); -+static int globexp1(const char *, glob_t *, size_t *); -+static int globexp2(const char *, const char *, glob_t *, int *, size_t *); -+static int match(char *, char *, char *); -+ -+int ismeta(char c) { -+ return c == M_ALL || c == M_END || c == M_NOT || c == M_ONE || c == M_RNG || c == M_SET; -+} -+ -+int -+glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) -+{ -+ const char *patnext; -+ size_t limit; -+ char *bufnext, *bufend, patbuf[MAXPATHLEN], prot; -+ -+ patnext = pattern; -+ if (!(flags & GLOB_APPEND)) { -+ pglob->gl_pathc = 0; -+ pglob->gl_pathv = NULL; -+ if (!(flags & GLOB_DOOFFS)) -+ pglob->gl_offs = 0; -+ } -+ if (flags & GLOB_LIMIT) { -+ limit = pglob->gl_matchc; -+ if (limit == 0) -+ limit = 131072; -+ } else -+ limit = 0; -+ pglob->gl_flags = flags & ~GLOB_MAGCHAR; -+ pglob->gl_errfunc = errfunc; -+ pglob->gl_matchc = 0; -+ -+ bufnext = patbuf; -+ bufend = bufnext + MAXPATHLEN - 1; -+ if (flags & GLOB_NOESCAPE) { -+ strncpy(bufnext, patnext, sizeof(patbuf)); -+ } else { -+ /* Protect the quoted characters. */ -+ while (bufend >= bufnext && *patnext != EOS) { -+ if (*patnext == QUOTE) { -+ if (*++patnext == EOS) { -+ *bufnext++ = QUOTE | M_PROTECT; -+ continue; -+ } -+ prot = M_PROTECT; -+ } else -+ prot = 0; -+ *bufnext++ = *patnext; -+ patnext++; -+ } -+ } -+ *bufnext = EOS; -+ -+ if (flags & GLOB_BRACE) -+ return globexp1(patbuf, pglob, &limit); -+ else -+ return glob0(patbuf, pglob, &limit); -+} -+ -+/* -+ * Expand recursively a glob {} pattern. When there is no more expansion -+ * invoke the standard globbing routine to glob the rest of the magic -+ * characters -+ */ -+static int -+globexp1(const char *pattern, glob_t *pglob, size_t *limit) -+{ -+ const char* ptr = pattern; -+ int rv; -+ -+ /* Protect a single {}, for find(1), like csh */ -+ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) -+ return glob0(pattern, pglob, limit); -+ -+ while ((ptr = strchr(ptr, LBRACE)) != NULL) -+ if (!globexp2(ptr, pattern, pglob, &rv, limit)) -+ return rv; -+ -+ return glob0(pattern, pglob, limit); -+} -+ -+ -+/* -+ * Recursive brace globbing helper. Tries to expand a single brace. -+ * If it succeeds then it invokes globexp1 with the new pattern. -+ * If it fails then it tries to glob the rest of the pattern and returns. -+ */ -+static int -+globexp2(const char *ptr, const char *pattern, glob_t *pglob, int *rv, size_t *limit) -+{ -+ int i; -+ char *lm, *ls; -+ const char *pe, *pm, *pm1, *pl; -+ char patbuf[MAXPATHLEN]; -+ -+ /* copy part up to the brace */ -+ for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) -+ continue; -+ *lm = EOS; -+ ls = lm; -+ -+ /* Find the balanced brace */ -+ for (i = 0, pe = ++ptr; *pe; pe++) -+ if (*pe == LBRACKET) { -+ /* Ignore everything between [] */ -+ for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) -+ continue; -+ if (*pe == EOS) { -+ /* -+ * We could not find a matching RBRACKET. -+ * Ignore and just look for RBRACE -+ */ -+ pe = pm; -+ } -+ } -+ else if (*pe == LBRACE) -+ i++; -+ else if (*pe == RBRACE) { -+ if (i == 0) -+ break; -+ i--; -+ } -+ -+ /* Non matching braces; just glob the pattern */ -+ if (i != 0 || *pe == EOS) { -+ *rv = glob0(patbuf, pglob, limit); -+ return 0; -+ } -+ -+ for (i = 0, pl = pm = ptr; pm <= pe; pm++) -+ switch (*pm) { -+ case LBRACKET: -+ /* Ignore everything between [] */ -+ for (pm1 = pm++; *pm != RBRACKET && *pm != EOS; pm++) -+ continue; -+ if (*pm == EOS) { -+ /* -+ * We could not find a matching RBRACKET. -+ * Ignore and just look for RBRACE -+ */ -+ pm = pm1; -+ } -+ break; -+ -+ case LBRACE: -+ i++; -+ break; -+ -+ case RBRACE: -+ if (i) { -+ i--; -+ break; -+ } -+ /* FALLTHROUGH */ -+ case COMMA: -+ if (i && *pm == COMMA) -+ break; -+ else { -+ /* Append the current string */ -+ for (lm = ls; (pl < pm); *lm++ = *pl++) -+ continue; -+ /* -+ * Append the rest of the pattern after the -+ * closing brace -+ */ -+ for (pl = pe + 1; (*lm++ = *pl++) != EOS;) -+ continue; -+ -+ /* Expand the current pattern */ -+ *rv = globexp1(patbuf, pglob, limit); -+ -+ /* move after the comma, to the next string */ -+ pl = pm + 1; -+ } -+ break; -+ -+ default: -+ break; -+ } -+ *rv = 0; -+ return 0; -+} -+ -+ -+ -+/* -+ * expand tilde from the passwd file. -+ */ -+static const char * -+globtilde(const char *pattern, char *patbuf, size_t patbuf_len, glob_t *pglob) -+{ -+ struct passwd *pwd; -+ char *h; -+ const char *p; -+ char *b, *eb; -+ -+ if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) -+ return pattern; -+ -+ /* -+ * Copy up to the end of the string or / -+ */ -+ eb = &patbuf[patbuf_len - 1]; -+ for (p = pattern + 1, h = (char *) patbuf; -+ h < (char *)eb && *p && *p != SLASH; *h++ = *p++) -+ continue; -+ -+ *h = EOS; -+ -+ if (((char *) patbuf)[0] == EOS) { -+ /* -+ * handle a plain ~ or ~/ by expanding $HOME first (iff -+ * we're not running setuid or setgid) and then trying -+ * the password file -+ */ -+#ifndef __GLIBC__ -+ if (issetugid() != 0 || -+ (h = getenv("HOME")) == NULL) { -+ if (((h = getlogin()) != NULL && -+ (pwd = getpwnam(h)) != NULL) || -+ (pwd = getpwuid(getuid())) != NULL) -+ h = pwd->pw_dir; -+ else -+ return pattern; -+ } -+#endif -+ } -+ else { -+ /* -+ * Expand a ~user -+ */ -+ if ((pwd = getpwnam((char*) patbuf)) == NULL) -+ return pattern; -+ else -+ h = pwd->pw_dir; -+ } -+ -+ /* Copy the home directory */ -+ for (b = patbuf; b < eb && *h; *b++ = *h++) -+ continue; -+ -+ /* Append the rest of the pattern */ -+ while (b < eb && (*b++ = *p++) != EOS) -+ continue; -+ *b = EOS; -+ -+ return patbuf; -+} -+ -+ -+/* -+ * The main glob() routine: compiles the pattern (optionally processing -+ * quotes), calls glob1() to do the real pattern matching, and finally -+ * sorts the list (unless unsorted operation is requested). Returns 0 -+ * if things went well, nonzero if errors occurred. -+ */ -+static int -+glob0(const char *pattern, glob_t *pglob, size_t *limit) -+{ -+ const char *qpatnext; -+ int err; -+ size_t oldpathc; -+ char *bufnext, c, patbuf[MAXPATHLEN]; -+ -+ qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob); -+ oldpathc = pglob->gl_pathc; -+ bufnext = patbuf; -+ -+ /* We don't need to check for buffer overflow any more. */ -+ while ((c = *qpatnext++) != EOS) { -+ switch (c) { -+ case LBRACKET: -+ c = *qpatnext; -+ if (c == NOT) -+ ++qpatnext; -+ if (*qpatnext == EOS || -+ strchr(qpatnext+1, RBRACKET) == NULL) { -+ *bufnext++ = LBRACKET; -+ if (c == NOT) -+ --qpatnext; -+ break; -+ } -+ *bufnext++ = M_SET; -+ if (c == NOT) -+ *bufnext++ = M_NOT; -+ c = *qpatnext++; -+ do { -+ *bufnext++ = c; -+ if (*qpatnext == RANGE && -+ (c = qpatnext[1]) != RBRACKET) { -+ *bufnext++ = M_RNG; -+ *bufnext++ = c; -+ qpatnext += 2; -+ } -+ } while ((c = *qpatnext++) != RBRACKET); -+ pglob->gl_flags |= GLOB_MAGCHAR; -+ *bufnext++ = M_END; -+ break; -+ case QUESTION: -+ pglob->gl_flags |= GLOB_MAGCHAR; -+ *bufnext++ = M_ONE; -+ break; -+ case STAR: -+ pglob->gl_flags |= GLOB_MAGCHAR; -+ /* collapse adjacent stars to one, -+ * to avoid exponential behavior -+ */ -+ if (bufnext == patbuf || bufnext[-1] != M_ALL) -+ *bufnext++ = M_ALL; -+ break; -+ default: -+ *bufnext++ = c; -+ break; -+ } -+ } -+ *bufnext = EOS; -+ -+ if ((err = glob1(patbuf, pglob, limit)) != 0) -+ return(err); -+ -+ /* -+ * If there was no match we are going to append the pattern -+ * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified -+ * and the pattern did not contain any magic characters -+ * GLOB_NOMAGIC is there just for compatibility with csh. -+ */ -+ if (pglob->gl_pathc == oldpathc) { -+ if (((pglob->gl_flags & GLOB_NOCHECK) || -+ ((pglob->gl_flags & GLOB_NOMAGIC) && -+ !(pglob->gl_flags & GLOB_MAGCHAR)))) -+ return(globextend(pattern, pglob, limit)); -+ else -+ return(GLOB_NOMATCH); -+ } -+ if (!(pglob->gl_flags & GLOB_NOSORT)) -+ qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, -+ pglob->gl_pathc - oldpathc, sizeof(char *), compare); -+ return(0); -+} -+ -+static int -+compare(const void *p, const void *q) -+{ -+ return(strcmp(*(char **)p, *(char **)q)); -+} -+ -+static int -+glob1(char *pattern, glob_t *pglob, size_t *limit) -+{ -+ char pathbuf[MAXPATHLEN]; -+ -+ /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ -+ if (*pattern == EOS) -+ return(0); -+ return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, -+ pattern, pglob, limit)); -+} -+ -+/* -+ * The functions glob2 and glob3 are mutually recursive; there is one level -+ * of recursion for each segment in the pattern that contains one or more -+ * meta characters. -+ */ -+static int -+glob2(char *pathbuf, char *pathend, char *pathend_last, char *pattern, -+ glob_t *pglob, size_t *limit) -+{ -+ struct stat sb; -+ char *p, *q; -+ int anymeta; -+ -+ /* -+ * Loop over pattern segments until end of pattern or until -+ * segment with meta character found. -+ */ -+ for (anymeta = 0;;) { -+ if (*pattern == EOS) { /* End of pattern? */ -+ *pathend = EOS; -+ if (g_lstat(pathbuf, &sb, pglob)) -+ return(0); -+ -+ if (((pglob->gl_flags & GLOB_MARK) && -+ pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) -+ || (S_ISLNK(sb.st_mode) && -+ (g_stat(pathbuf, &sb, pglob) == 0) && -+ S_ISDIR(sb.st_mode)))) { -+ if (pathend + 1 > pathend_last) -+ return (GLOB_ABORTED); -+ *pathend++ = SEP; -+ *pathend = EOS; -+ } -+ ++pglob->gl_matchc; -+ return(globextend(pathbuf, pglob, limit)); -+ } -+ -+ /* Find end of next segment, copy tentatively to pathend. */ -+ q = pathend; -+ p = pattern; -+ while (*p != EOS && *p != SEP) { -+ if (ismeta(*p)) -+ anymeta = 1; -+ if (q + 1 > pathend_last) -+ return (GLOB_ABORTED); -+ *q++ = *p++; -+ } -+ -+ if (!anymeta) { /* No expansion, do next segment. */ -+ pathend = q; -+ pattern = p; -+ while (*pattern == SEP) { -+ if (pathend + 1 > pathend_last) -+ return (GLOB_ABORTED); -+ *pathend++ = *pattern++; -+ } -+ } else /* Need expansion, recurse. */ -+ return(glob3(pathbuf, pathend, pathend_last, pattern, p, -+ pglob, limit)); -+ } -+ /* NOTREACHED */ -+} -+ -+static int -+glob3(char *pathbuf, char *pathend, char *pathend_last, -+ char *pattern, char *restpattern, -+ glob_t *pglob, size_t *limit) -+{ -+ struct dirent *dp; -+ DIR *dirp; -+ int err; -+ char buf[MAXPATHLEN]; -+ -+ /* -+ * The readdirfunc declaration can't be prototyped, because it is -+ * assigned, below, to two functions which are prototyped in glob.h -+ * and dirent.h as taking pointers to differently typed opaque -+ * structures. -+ */ -+ struct dirent *(*readdirfunc)(); -+ -+ if (pathend > pathend_last) -+ return (GLOB_ABORTED); -+ *pathend = EOS; -+ errno = 0; -+ -+ if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { -+ /* TODO: don't call for ENOENT or ENOTDIR? */ -+ if (pglob->gl_errfunc) { -+ if (pglob->gl_errfunc(buf, errno) || -+ pglob->gl_flags & GLOB_ERR) -+ return (GLOB_ABORTED); -+ } -+ return(0); -+ } -+ -+ err = 0; -+ -+ /* Search directory for matching names. */ -+ if (pglob->gl_flags & GLOB_ALTDIRFUNC) -+ readdirfunc = pglob->gl_readdir; -+ else -+ readdirfunc = readdir; -+ while ((dp = (*readdirfunc)(dirp))) { -+ char *sc; -+ char *dc; -+ -+ /* Initial DOT must be matched literally. */ -+ if (dp->d_name[0] == DOT && *pattern != DOT) -+ continue; -+ dc = pathend; -+ sc = dp->d_name; -+ while (dc < pathend_last) { -+ if ((*dc++ = *sc) == EOS) -+ break; -+ sc++; -+ } -+ if (!match(pathend, pattern, restpattern)) { -+ *pathend = EOS; -+ continue; -+ } -+ err = glob2(pathbuf, --dc, pathend_last, restpattern, -+ pglob, limit); -+ if (err) -+ break; -+ } -+ -+ if (pglob->gl_flags & GLOB_ALTDIRFUNC) -+ (*pglob->gl_closedir)(dirp); -+ else -+ closedir(dirp); -+ return(err); -+} -+ -+ -+/* -+ * Extend the gl_pathv member of a glob_t structure to accomodate a new item, -+ * add the new item, and update gl_pathc. -+ * -+ * This assumes the BSD realloc, which only copies the block when its size -+ * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic -+ * behavior. -+ * -+ * Return 0 if new item added, error code if memory couldn't be allocated. -+ * -+ * Invariant of the glob_t structure: -+ * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and -+ * gl_pathv points to (gl_offs + gl_pathc + 1) items. -+ */ -+static int -+globextend(const char *path, glob_t *pglob, size_t *limit) -+{ -+ char **pathv; -+ size_t i, newsize, len; -+ char *copy; -+ const char *p; -+ -+ if (*limit && pglob->gl_pathc > *limit) { -+ errno = 0; -+ return (GLOB_NOSPACE); -+ } -+ -+ newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs); -+ pathv = pglob->gl_pathv ? -+ realloc((char *)pglob->gl_pathv, newsize) : -+ malloc(newsize); -+ if (pathv == NULL) { -+ if (pglob->gl_pathv) { -+ free(pglob->gl_pathv); -+ pglob->gl_pathv = NULL; -+ } -+ return(GLOB_NOSPACE); -+ } -+ -+ if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { -+ /* first time around -- clear initial gl_offs items */ -+ pathv += pglob->gl_offs; -+ for (i = pglob->gl_offs + 1; --i > 0; ) -+ *--pathv = NULL; -+ } -+ pglob->gl_pathv = pathv; -+ -+ for (p = path; *p++;) -+ continue; -+ len = (size_t)(p - path); /* XXX overallocation */ -+ if ((copy = malloc(len)) != NULL) { -+ strncpy(copy, path, len); -+ pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; -+ } -+ pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; -+ return(copy == NULL ? GLOB_NOSPACE : 0); -+} -+ -+/* -+ * pattern matching function for filenames. Each occurrence of the * -+ * pattern causes a recursion level. -+ */ -+static int -+match(char *name, char *pat, char *patend) -+{ -+ int ok, negate_range; -+ char c, k; -+ -+ while (pat < patend) { -+ c = *pat++; -+ switch (c & M_MASK) { -+ case M_ALL: -+ if (pat == patend) -+ return(1); -+ do -+ if (match(name, pat, patend)) -+ return(1); -+ while (*name++ != EOS); -+ return(0); -+ case M_ONE: -+ if (*name++ == EOS) -+ return(0); -+ break; -+ case M_SET: -+ ok = 0; -+ if ((k = *name++) == EOS) -+ return(0); -+ if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) -+ ++pat; -+ while (((c = *pat++) & M_MASK) != M_END) -+ if ((*pat & M_MASK) == M_RNG) { -+ // NOTE(gabor): This used to be as below, but I took out the collate.h -+ // if (__collate_load_error ? -+ // CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]) : -+ // __collate_range_cmp(CHAR(c), CHAR(k)) <= 0 -+ // && __collate_range_cmp(CHAR(k), CHAR(pat[1])) <= 0 -+ // ) -+ -+ if (c <= k && k <= pat[1]) -+ ok = 1; -+ pat += 2; -+ } else if (c == k) -+ ok = 1; -+ if (ok == negate_range) -+ return(0); -+ break; -+ default: -+ if (*name++ != c) -+ return(0); -+ break; -+ } -+ } -+ return(*name == EOS); -+} -+ -+/* Free allocated data belonging to a glob_t structure. */ -+void -+globfree(glob_t *pglob) -+{ -+ size_t i; -+ char **pp; -+ -+ if (pglob->gl_pathv != NULL) { -+ pp = pglob->gl_pathv + pglob->gl_offs; -+ for (i = pglob->gl_pathc; i--; ++pp) -+ if (*pp) -+ free(*pp); -+ free(pglob->gl_pathv); -+ pglob->gl_pathv = NULL; -+ } -+} -+ -+static int -+g_stat(char *fn, struct stat *sb, glob_t *pglob) -+{ -+ if (pglob->gl_flags & GLOB_ALTDIRFUNC) -+ return((*pglob->gl_stat)(fn, sb)); -+ return(stat(fn, sb)); -+} -+ -+static DIR * -+g_opendir(char *str, glob_t *pglob) -+{ -+ if (pglob->gl_flags & GLOB_ALTDIRFUNC) -+ return((*pglob->gl_opendir)(str)); -+ -+ return(opendir(str)); -+} -+ -+static int -+g_lstat(char *fn, struct stat *sb, glob_t *pglob) -+{ -+ if (pglob->gl_flags & GLOB_ALTDIRFUNC) -+ return((*pglob->gl_lstat)(fn, sb)); -+ return(lstat(fn, sb)); -+} -diff --git a/shell/glob.h b/shell/glob.h -new file mode 100644 -index 000000000..e8e65786d ---- /dev/null -+++ b/shell/glob.h -@@ -0,0 +1,113 @@ -+/* -+ * Modified for the Android NDK by Gabor Cselle, http://www.gaborcselle.com/ -+ * Tested with Android NDK version 5b: http://developer.android.com/sdk/ndk/index.html -+ * Last modified: March 3 2011 -+ * -+ * Copyright (c) 1989, 1993 -+ * The Regents of the University of California. All rights reserved. -+ * -+ * This code is derived from software contributed to Berkeley by -+ * Guido van Rossum. -+ * -+ * Redistribution and use in source and binary forms, with or without -+ * modification, are permitted provided that the following conditions -+ * are met: -+ * 1. Redistributions of source code must retain the above copyright -+ * notice, this list of conditions and the following disclaimer. -+ * 2. Redistributions in binary form must reproduce the above copyright -+ * notice, this list of conditions and the following disclaimer in the -+ * documentation and/or other materials provided with the distribution. -+ * 3. All advertising materials mentioning features or use of this software -+ * must display the following acknowledgement: -+ * This product includes software developed by the University of -+ * California, Berkeley and its contributors. -+ * 4. Neither the name of the University nor the names of its contributors -+ * may be used to endorse or promote products derived from this software -+ * without specific prior written permission. -+ * -+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -+ * SUCH DAMAGE. -+ * -+ * @(#)glob.h 8.1 (Berkeley) 6/2/93 -+ * $FreeBSD$ -+ */ -+ -+#ifndef _GLOB_H_ -+#define _GLOB_H_ -+ -+#include -+//#include -+ -+#ifndef _SIZE_T_DECLARED -+typedef __size_t size_t; -+#define _SIZE_T_DECLARED -+#endif -+ -+struct stat; -+typedef struct { -+ size_t gl_pathc; /* Count of total paths so far. */ -+ size_t gl_matchc; /* Count of paths matching pattern. */ -+ size_t gl_offs; /* Reserved at beginning of gl_pathv. */ -+ int gl_flags; /* Copy of flags parameter to glob. */ -+ char **gl_pathv; /* List of paths matching pattern. */ -+ /* Copy of errfunc parameter to glob. */ -+ int (*gl_errfunc)(const char *, int); -+ -+ /* -+ * Alternate filesystem access methods for glob; replacement -+ * versions of closedir(3), readdir(3), opendir(3), stat(2) -+ * and lstat(2). -+ */ -+ void (*gl_closedir)(void *); -+ struct dirent *(*gl_readdir)(void *); -+ void *(*gl_opendir)(const char *); -+ int (*gl_lstat)(const char *, struct stat *); -+ int (*gl_stat)(const char *, struct stat *); -+} glob_t; -+ -+#if __POSIX_VISIBLE >= 199209 -+/* Believed to have been introduced in 1003.2-1992 */ -+#define GLOB_APPEND 0x0001 /* Append to output from previous call. */ -+#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ -+#define GLOB_ERR 0x0004 /* Return on error. */ -+#define GLOB_MARK 0x0008 /* Append / to matching directories. */ -+#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ -+#define GLOB_NOSORT 0x0020 /* Don't sort. */ -+#define GLOB_NOESCAPE 0x2000 /* Disable backslash escaping. */ -+ -+/* Error values returned by glob(3) */ -+#define GLOB_NOSPACE (-1) /* Malloc call failed. */ -+#define GLOB_ABORTED (-2) /* Unignored error. */ -+#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK was not set. */ -+#define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */ -+#endif /* __POSIX_VISIBLE >= 199209 */ -+ -+#if __BSD_VISIBLE -+#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ -+#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ -+#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ -+#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ -+#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ -+#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ -+#define GLOB_LIMIT 0x1000 /* limit number of returned paths */ -+ -+/* source compatibility, these are the old names */ -+#define GLOB_MAXPATH GLOB_LIMIT -+#define GLOB_ABEND GLOB_ABORTED -+#endif /* __BSD_VISIBLE */ -+ -+__BEGIN_DECLS -+int glob(const char *, int, int (*)(const char *, int), glob_t *); -+void globfree(glob_t *); -+__END_DECLS -+ -+#endif /* !_GLOB_H_ */ -diff --git a/shell/hush.c b/shell/hush.c -index d111f0cc5..af7f0d50c 100644 ---- a/shell/hush.c -+++ b/shell/hush.c -@@ -331,6 +331,7 @@ - //applet:IF_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, hush)) - - //kbuild:lib-$(CONFIG_SHELL_HUSH) += hush.o match.o shell_common.o -+//kbuild:lib-$(CONFIG_SHELL_HUSH) += glob.o sigisemptyset.o - //kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o - - /* -i (interactive) is also accepted, -@@ -348,7 +349,7 @@ - ) - # include /* for malloc_trim */ - #endif --#include -+#include "glob.h" - /* #include */ - #if ENABLE_HUSH_CASE - # include -diff --git a/shell/sigisemptyset.c b/shell/sigisemptyset.c -new file mode 100644 -index 000000000..649b974c0 ---- /dev/null -+++ b/shell/sigisemptyset.c -@@ -0,0 +1,8 @@ -+#include -+ -+int sigisemptyset(const sigset_t *set) -+{ -+ sigset_t empty; -+ sigemptyset(&empty); -+ return memcmp(&empty, set, sizeof(sigset_t)) == 0; -+} --- -2.45.2 - diff --git a/patches/0020-glob-minor-adjustments-to-support-unified-headers.patch b/patches/0020-glob-minor-adjustments-to-support-unified-headers.patch deleted file mode 100644 index c969477..0000000 --- a/patches/0020-glob-minor-adjustments-to-support-unified-headers.patch +++ /dev/null @@ -1,43 +0,0 @@ -From fcf2cf5c422df1f347eb24312722b5a01ae3ca44 Mon Sep 17 00:00:00 2001 -From: John Wu -Date: Sun, 12 Aug 2018 18:31:26 +0800 -Subject: [PATCH 20/35] glob: minor adjustments to support unified headers - ---- - shell/glob.h | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/shell/glob.h b/shell/glob.h -index e8e65786d..c274a8f6a 100644 ---- a/shell/glob.h -+++ b/shell/glob.h -@@ -47,7 +47,7 @@ - #include - //#include - --#ifndef _SIZE_T_DECLARED -+#if !defined(_SIZE_T_DECLARED) && !defined(__ANDROID__) - typedef __size_t size_t; - #define _SIZE_T_DECLARED - #endif -@@ -74,7 +74,7 @@ typedef struct { - int (*gl_stat)(const char *, struct stat *); - } glob_t; - --#if __POSIX_VISIBLE >= 199209 -+#if __POSIX_VISIBLE >= 199209 || defined(__ANDROID__) - /* Believed to have been introduced in 1003.2-1992 */ - #define GLOB_APPEND 0x0001 /* Append to output from previous call. */ - #define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ -@@ -91,7 +91,7 @@ typedef struct { - #define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */ - #endif /* __POSIX_VISIBLE >= 199209 */ - --#if __BSD_VISIBLE -+#if __BSD_VISIBLE || defined(__ANDROID__) - #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ - #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ - #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ --- -2.45.2 - diff --git a/patches/0021-modinfo-modprobe-use-ifdef-block-for-android-without.patch b/patches/0021-modinfo-modprobe-use-ifdef-block-for-android-without.patch deleted file mode 100644 index 3ba0910..0000000 --- a/patches/0021-modinfo-modprobe-use-ifdef-block-for-android-without.patch +++ /dev/null @@ -1,153 +0,0 @@ -From 3b78ffa6a62431a85fd47ea716b5d8c6a899ae51 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Thu, 6 May 2021 16:30:26 -0300 -Subject: [PATCH 21/35] modinfo/modprobe: use ifdef block for android - without-utsrel modules path - -and fixes the modules.dep requirement, it is now optional... - -Patch by Tanguy Pruvot -Change-Id: Ifccb530fa23b021fd12e2395f5d0c66600b25c04 -from https://github.com/tpruvot/android_external_busybox - -and commit 2df42d3971f1e260e67c3fa4831cb9195fb276c4 -from https://github.com/tpruvot/android_external_busybox - -Rebased for busybox 1.33.1 by Chris Renshaw ---- - modutils/modinfo.c | 33 +++++++++++++++++++++++++++++---- - modutils/modprobe.c | 18 +++++++++++++++++- - 2 files changed, 46 insertions(+), 5 deletions(-) - -diff --git a/modutils/modinfo.c b/modutils/modinfo.c -index 0a86c3296..de6b24b4d 100644 ---- a/modutils/modinfo.c -+++ b/modutils/modinfo.c -@@ -20,6 +20,10 @@ - #include "libbb.h" - #include "modutils.h" - -+#if defined(ANDROID) || defined(__ANDROID__) -+#define DONT_USE_UTS_REL_FOLDER -+#endif -+ - static const char *const shortcuts[] ALIGN_PTR = { - "filename", // -n - "author", // -a -@@ -63,7 +67,7 @@ static void modinfo(const char *path, const char *version, - { - size_t len; - int j; -- char *ptr, *the_module; -+ char *ptr, *fullpath, *the_module; - char *allocated; - int tags = option_mask32; - -@@ -74,8 +78,14 @@ static void modinfo(const char *path, const char *version, - if (path[0] == '/') - return; - /* Newer depmod puts relative paths in modules.dep */ -- path = allocated = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path); -- the_module = xmalloc_open_zipped_read_close(path, &len); -+ fullpath = allocated = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path); -+ the_module = xmalloc_open_zipped_read_close(fullpath, &len); -+#ifdef DONT_USE_UTS_REL_FOLDER -+ if (!the_module) { -+ fullpath = allocated = xasprintf("%s/%s", CONFIG_DEFAULT_MODULES_DIR, path); -+ the_module = xmalloc_open_zipped_read_close(fullpath, &len); -+ } -+#endif - if (!the_module) { - bb_error_msg("module '%s' not found", path); - goto ret; -@@ -156,9 +166,23 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv) - uname(&uts); - parser = config_open2( - xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, uts.release, CONFIG_DEFAULT_DEPMOD_FILE), -- xfopen_for_read -+ fopen_for_read - ); - -+#ifdef DONT_USE_UTS_REL_FOLDER -+ if (!parser) { -+ parser = config_open2( -+ xasprintf("%s/%s", CONFIG_DEFAULT_MODULES_DIR, CONFIG_DEFAULT_DEPMOD_FILE), -+ fopen_for_read -+ ); -+ } -+ -+ if (!parser) { -+ strcpy(uts.release,""); -+ goto no_modules_dep; -+ } -+#endif -+ - while (config_read(parser, tokens, 2, 1, "# \t", PARSE_NORMAL)) { - colon = last_char_is(tokens[0], ':'); - if (colon == NULL) -@@ -175,6 +199,7 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv) - if (ENABLE_FEATURE_CLEAN_UP) - config_close(parser); - -+no_modules_dep: - for (i = 0; argv[i]; i++) { - if (argv[i][0]) { - modinfo(argv[i], uts.release, field); -diff --git a/modutils/modprobe.c b/modutils/modprobe.c -index 235706fd5..4f4ee11e1 100644 ---- a/modutils/modprobe.c -+++ b/modutils/modprobe.c -@@ -172,6 +172,10 @@ static const char modprobe_longopts[] ALIGN1 = - #define MODULE_FLAG_BLACKLISTED 0x0008 - #define MODULE_FLAG_BUILTIN 0x0010 - -+#if defined(ANDROID) || defined(__ANDROID__) -+#define DONT_USE_UTS_REL_FOLDER -+#endif -+ - struct globals { - llist_t *probes; /* MEs of module(s) requested on cmdline */ - #if ENABLE_FEATURE_CMDLINE_MODULE_OPTIONS -@@ -474,10 +478,17 @@ static int do_modprobe(struct module_entry *m) - #endif - - if (option_mask32 & OPT_SHOW_DEPS) { -+#ifndef DONT_USE_UTS_REL_FOLDER - printf(options ? "insmod %s/%s/%s %s\n" - : "insmod %s/%s/%s\n", - CONFIG_DEFAULT_MODULES_DIR, G.uts.release, fn, - options); -+#else -+ printf(options ? "insmod %s/%s %s\n" -+ : "insmod %s/%s\n", -+ CONFIG_DEFAULT_MODULES_DIR, fn, -+ options); -+#endif - free(options); - continue; - } -@@ -559,6 +570,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) - int rc; - unsigned opt; - struct module_entry *me; -+ struct stat info; - - INIT_G(); - -@@ -570,8 +582,12 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) - - /* Goto modules location */ - xchdir(CONFIG_DEFAULT_MODULES_DIR); -+#ifndef DONT_USE_UTS_REL_FOLDER - uname(&G.uts); -- xchdir(G.uts.release); -+ if (stat(G.uts.release, &info) == 0) { -+ xchdir(G.uts.release); -+ } -+#endif - - if (opt & OPT_LIST_ONLY) { - int i; --- -2.45.2 - diff --git a/patches/0022-depmod-fix-syntax-with-modules-in-parameter.patch b/patches/0022-depmod-fix-syntax-with-modules-in-parameter.patch deleted file mode 100644 index ee7f125..0000000 --- a/patches/0022-depmod-fix-syntax-with-modules-in-parameter.patch +++ /dev/null @@ -1,32 +0,0 @@ -From c48e14ccd0add532a5b139c8b400fa283bd9bfb2 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Mon, 12 Sep 2016 16:55:01 -0300 -Subject: [PATCH 22/35] depmod: fix syntax with modules in parameter - -Patch by Tanguy Pruvot -Change-Id: I21b8664db01cf0132db82f8d6caa1a0e77e71004 -from https://github.com/tpruvot/android_external_busybox -Rebased for busybox 1.25.0 by Chris Renshaw ---- - modutils/depmod.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/modutils/depmod.c b/modutils/depmod.c -index bb42bbefe..5e4c4c538 100644 ---- a/modutils/depmod.c -+++ b/modutils/depmod.c -@@ -49,7 +49,10 @@ static int FAST_FUNC parse_module(struct recursive_state *state, - image = xmalloc_open_zipped_read_close(fname, &len); - - e = moddb_get_or_create(modules, bb_get_last_path_component_nostrip(fname)); -- e->name = xstrdup(fname + 2); /* skip "./" */ -+ if (strncmp(fname, "./", 2) == 0) -+ e->name = xstrdup(fname + 2); -+ else -+ e->name = xstrdup(fname); - - for (ptr = image; ptr < image + len - 10; ptr++) { - if (is_prefixed_with(ptr, "depends=")) { --- -2.45.2 - diff --git a/patches/0023-fix-reboot-poweroff-hack-android_reboot-support.patch b/patches/0023-fix-reboot-poweroff-hack-android_reboot-support.patch deleted file mode 100644 index 56cf612..0000000 --- a/patches/0023-fix-reboot-poweroff-hack-android_reboot-support.patch +++ /dev/null @@ -1,108 +0,0 @@ -From 2c443ce15e52b95157ce009f920e19792e00a277 Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Mon, 26 Jun 2017 23:53:06 -0300 -Subject: [PATCH 23/35] fix reboot+poweroff: hack android_reboot support - -based on 'reboot.c' and 'halt.c' patches from CyanogenMod: -https://github.com/CyanogenMod/android_external_busybox/commit/8aeb3719294721f744239ced474d159f073eef55#diff-51036c2b1c4282b63402a0e0286a066a -https://github.com/CyanogenMod/android_external_busybox/commit/8aeb3719294721f744239ced474d159f073eef55#diff-fa7fd08ce03ea9138df81c149792b371 -https://github.com/CyanogenMod/android_external_busybox/commit/d0b802581eb4f83e81b652f0b59b8b9b98105e66 - -then updated and simplified using: -https://github.com/android/platform_system_core/blob/master/libcutils/android_reboot.c -https://github.com/android/platform_system_core/blob/master/libcutils/include/cutils/android_reboot.h - -and added work around to write the property value directly via shell since property_set and __system_property_set require linkage to libcutils and/or libc ---- - init/halt.c | 27 +++++++++++++++++++++++++++ - init/reboot.c | 33 +++++++++++++++++++++++++++++++++ - 2 files changed, 60 insertions(+) - create mode 100644 init/reboot.c - -diff --git a/init/halt.c b/init/halt.c -index fe3cb9e75..895009972 100644 ---- a/init/halt.c -+++ b/init/halt.c -@@ -94,6 +94,10 @@ - #include "libbb.h" - #include "reboot.h" - -+#ifdef __BIONIC__ -+#include "reboot.c" -+#endif -+ - #if ENABLE_FEATURE_WTMP - #include - -@@ -204,6 +208,29 @@ int halt_main(int argc UNUSED_PARAM, char **argv) - if (!(flags & 2)) /* no -n */ - sync(); - -+#ifdef __BIONIC__ -+ char *mode[4]; -+ int c = 1; -+ mode[0] = strdup("reboot"); -+ mode[1] = mode[2] = mode[3] = NULL; -+ switch (which) { -+ case 0: -+ case 1: -+ //-p for halt -+ mode[1] = strdup("-p"); -+ c = 2; -+ break; -+ case 2: -+ //reboot -+ if (argc > 1) { -+ mode[1] = strdup(argv[1]); -+ c = 2; -+ } -+ break; -+ } -+ return reboot_android(c, mode); -+#endif -+ - /* Perform action. */ - rc = 1; - if (!(flags & 4)) { /* no -f */ -diff --git a/init/reboot.c b/init/reboot.c -new file mode 100644 -index 000000000..97fe523a7 ---- /dev/null -+++ b/init/reboot.c -@@ -0,0 +1,33 @@ -+#include -+#include -+#include -+ -+int reboot_android(int argc, char *argv[]) -+{ -+ int ret; -+ -+ const char* restart_cmd = NULL; -+ char* prop_value; -+ char* prop_cmd; -+ -+ restart_cmd = "reboot"; -+ while (true) { -+ int c = getopt(argc, argv, "p"); -+ if (c == EOF) -+ break; -+ switch (c) { -+ case 'p': -+ restart_cmd = "shutdown"; -+ break; -+ } -+ } -+ -+ if (argc > optind) -+ asprintf(&prop_value, "%s,%s", restart_cmd, argv[optind]); -+ else -+ asprintf(&prop_value, "%s", restart_cmd); -+ -+ asprintf(&prop_cmd, "setprop sys.powerctl %s", prop_value); -+ ret = execlp("sh", "sh", "-c", prop_cmd, NULL); -+ return ret; -+} --- -2.45.2 - diff --git a/patches/0024-fix-nslookup-add-libres-a-dietlibc-resolver.patch b/patches/0024-fix-nslookup-add-libres-a-dietlibc-resolver.patch deleted file mode 100644 index 99b4eaa..0000000 --- a/patches/0024-fix-nslookup-add-libres-a-dietlibc-resolver.patch +++ /dev/null @@ -1,1245 +0,0 @@ -From adb9e131ce65e966f95c5f682e8512b5f745683d Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Sat, 21 Jul 2018 20:02:13 -0300 -Subject: [PATCH 24/35] fix nslookup, add libres, a dietlibc resolver - -Using bionic's resolver functions does not allow changing the dns -server. Use dietlibc's resolver code instead (see package libres-devel) - -Patch by Tias Guns , based on 'dietlibc-resolver' and -'libres-0.32-1' by Dan Drown -http://dan.drown.org/android/src/busybox/ -http://dan.drown.org/android/src/libres/ - -Rebased for busybox 1.29.1 by Chris Renshaw ---- - Makefile | 1 + - libres/Kbuild.src | 11 +++ - libres/Makefile | 32 +++++++ - libres/README | 5 + - libres/dietdns.h | 189 ++++++++++++++++++++++++++++++++++++++ - libres/dn_expand.c | 12 +++ - libres/dnscruft.c | 119 ++++++++++++++++++++++++ - libres/dnscruft2.c | 132 ++++++++++++++++++++++++++ - libres/dnscruft3.c | 6 ++ - libres/freeaddrinfo.c | 14 +++ - libres/gai_strerror.c | 14 +++ - libres/getaddrinfo.c | 137 +++++++++++++++++++++++++++ - libres/gethostbyname2_r.c | 35 +++++++ - libres/h_errno.c | 1 + - libres/res_init.c | 12 +++ - libres/res_mkquery.c | 85 +++++++++++++++++ - libres/res_query.c | 81 ++++++++++++++++ - libres/test.c | 105 +++++++++++++++++++++ - networking/nslookup.c | 27 +++--- - 19 files changed, 1005 insertions(+), 13 deletions(-) - create mode 100644 libres/Kbuild.src - create mode 100644 libres/Makefile - create mode 100644 libres/README - create mode 100644 libres/dietdns.h - create mode 100644 libres/dn_expand.c - create mode 100644 libres/dnscruft.c - create mode 100644 libres/dnscruft2.c - create mode 100644 libres/dnscruft3.c - create mode 100644 libres/freeaddrinfo.c - create mode 100644 libres/gai_strerror.c - create mode 100644 libres/getaddrinfo.c - create mode 100644 libres/gethostbyname2_r.c - create mode 100644 libres/h_errno.c - create mode 100644 libres/res_init.c - create mode 100644 libres/res_mkquery.c - create mode 100644 libres/res_query.c - create mode 100644 libres/test.c - -diff --git a/Makefile b/Makefile -index fa8cb7614..13e857655 100644 ---- a/Makefile -+++ b/Makefile -@@ -477,6 +477,7 @@ libs-y := \ - init/ \ - libbb/ \ - libpwdgrp/ \ -+ libres/ \ - loginutils/ \ - mailutils/ \ - miscutils/ \ -diff --git a/libres/Kbuild.src b/libres/Kbuild.src -new file mode 100644 -index 000000000..abd4194a0 ---- /dev/null -+++ b/libres/Kbuild.src -@@ -0,0 +1,11 @@ -+# Makefile for busybox -+# -+# Copyright (C) 2012-2012 by Tias Guns -+# -+# Licensed under GPLv2, see file LICENSE in this source tree. -+ -+lib-$(CONFIG_NSLOOKUP) += getaddrinfo.o gethostbyname2_r.o freeaddrinfo.o -+lib-$(CONFIG_NSLOOKUP) += dnscruft.o dnscruft2.o dnscruft3.o -+lib-$(CONFIG_NSLOOKUP) += res_init.o res_query.o res_mkquery.o -+lib-$(CONFIG_NSLOOKUP) += h_errno.o gai_strerror.o -+lib-$(CONFIG_NSLOOKUP) += dn_expand.o -diff --git a/libres/Makefile b/libres/Makefile -new file mode 100644 -index 000000000..4a5688832 ---- /dev/null -+++ b/libres/Makefile -@@ -0,0 +1,32 @@ -+CC=agcc -+ -+OBJECTS=getaddrinfo.o -+OBJECTS+=gethostbyname2_r.o -+OBJECTS+=dnscruft.o -+OBJECTS+=dnscruft2.o -+OBJECTS+=dnscruft3.o -+OBJECTS+=h_errno.o -+OBJECTS+=res_query.o -+OBJECTS+=res_mkquery.o -+OBJECTS+=gai_strerror.o -+OBJECTS+=freeaddrinfo.o -+OBJECTS+=res_init.o -+OBJECTS+=dn_expand.o -+ -+CFLAGS+=-Wall -+ -+all: libres.a test -+clean: -+ rm -f $(OBJECTS) libres.a test.o test -+ -+test: libres.a test.o -+ $(CC) $(CFLAGS) -o test test.o libres.a -+ -+libres.a: $(OBJECTS) -+ ar r libres.a $(OBJECTS) -+ ranlib libres.a -+ -+.PHONY: all clean -+ -+%.o: %.c dietdns.h -+ $(CC) $(CFLAGS) -c $< -diff --git a/libres/README b/libres/README -new file mode 100644 -index 000000000..cab8e474d ---- /dev/null -+++ b/libres/README -@@ -0,0 +1,5 @@ -+all these files are from dietlibc, modified to fit as a plug-in resolver -+ -+Work by Dan Drown, called libres-0.32-1 -+available at: -+http://dan.drown.org/android/src/libres/ -diff --git a/libres/dietdns.h b/libres/dietdns.h -new file mode 100644 -index 000000000..9ae0b4de9 ---- /dev/null -+++ b/libres/dietdns.h -@@ -0,0 +1,189 @@ -+#ifndef __DIETDNS_H_ -+#define __DIETDNS_H_ -+ -+#define DIET_MAXDNAME 1025 /* maximum domain name */ -+#define DIET_PACKETSZ 512 -+ -+#define DIET_MAXNS 8 /* max # name servers we'll track */ -+#define DIET_MAXDNSRCH 6 /* max # domains in search path */ -+#define DIET_MAXRESOLVSORT 10 /* number of net to sort on */ -+ -+struct diet_res_state { -+ int retrans; /* retransmission time interval */ -+ int retry; /* number of times to retransmit */ -+ unsigned long options; /* option flags - see below. */ -+ int nscount; /* number of name servers */ -+ struct sockaddr_in -+ nsaddr_list[DIET_MAXNS]; /* address of name server */ -+#define nsaddr nsaddr_list[0] /* for backward compatibility */ -+ unsigned short id; /* current message id */ -+ char *dnsrch[DIET_MAXDNSRCH+1]; /* components of domain to search */ -+ char defdname[256]; /* default domain (deprecated) */ -+ unsigned long pfcode; /* RES_PRF_ flags - see below. */ -+ unsigned ndots:4; /* threshold for initial abs. query */ -+ unsigned nsort:4; /* number of elements in sort_list[] */ -+ char unused[3]; -+ struct { -+ struct in_addr addr; -+ uint32_t mask; -+ } sort_list[DIET_MAXRESOLVSORT]; -+ char pad[72]; -+}; -+ -+/* -+ * Values for class field -+ */ -+enum diet_ns_class { -+ diet_ns_c_invalid = 0, /* Cookie. */ -+ diet_ns_c_in = 1, /* Internet. */ -+ diet_ns_c_2 = 2, /* unallocated/unsupported. */ -+ diet_ns_c_chaos = 3, /* MIT Chaos-net. */ -+ diet_ns_c_hs = 4, /* MIT Hesiod. */ -+ /* Query class values which do not appear in resource records */ -+ diet_ns_c_none = 254, /* for prereq. sections in update requests */ -+ diet_ns_c_any = 255, /* Wildcard match. */ -+ diet_ns_c_max = 65536 -+}; -+ -+#define DIET_C_IN diet_ns_c_in -+ -+/* -+ * Currently defined opcodes. -+ */ -+enum diet_ns_opcode { -+ diet_ns_o_query = 0, /* Standard query. */ -+ diet_ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ -+ diet_ns_o_status = 2, /* Name server status query (unsupported). */ -+ /* Opcode 3 is undefined/reserved. */ -+ diet_ns_o_notify = 4, /* Zone change notification. */ -+ diet_ns_o_update = 5, /* Zone update message. */ -+ diet_ns_o_max = 6 -+}; -+ -+#define DIET_QUERY diet_ns_o_query -+ -+/* -+ * Currently defined type values for resources and queries. -+ */ -+enum diet_ns_type { -+ diet_ns_t_invalid = 0, /* Cookie. */ -+ diet_ns_t_a = 1, /* Host address. */ -+ diet_ns_t_ns = 2, /* Authoritative server. */ -+ diet_ns_t_md = 3, /* Mail destination. */ -+ diet_ns_t_mf = 4, /* Mail forwarder. */ -+ diet_ns_t_cname = 5, /* Canonical name. */ -+ diet_ns_t_soa = 6, /* Start of authority zone. */ -+ diet_ns_t_mb = 7, /* Mailbox domain name. */ -+ diet_ns_t_mg = 8, /* Mail group member. */ -+ diet_ns_t_mr = 9, /* Mail rename name. */ -+ diet_ns_t_null = 10, /* Null resource record. */ -+ diet_ns_t_wks = 11, /* Well known service. */ -+ diet_ns_t_ptr = 12, /* Domain name pointer. */ -+ diet_ns_t_hinfo = 13, /* Host information. */ -+ diet_ns_t_minfo = 14, /* Mailbox information. */ -+ diet_ns_t_mx = 15, /* Mail routing information. */ -+ diet_ns_t_txt = 16, /* Text strings. */ -+ diet_ns_t_rp = 17, /* Responsible person. */ -+ diet_ns_t_afsdb = 18, /* AFS cell database. */ -+ diet_ns_t_x25 = 19, /* X_25 calling address. */ -+ diet_ns_t_isdn = 20, /* ISDN calling address. */ -+ diet_ns_t_rt = 21, /* Router. */ -+ diet_ns_t_nsap = 22, /* NSAP address. */ -+ diet_ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ -+ diet_ns_t_sig = 24, /* Security signature. */ -+ diet_ns_t_key = 25, /* Security key. */ -+ diet_ns_t_px = 26, /* X.400 mail mapping. */ -+ diet_ns_t_gpos = 27, /* Geographical position (withdrawn). */ -+ diet_ns_t_aaaa = 28, /* Ip6 Address. */ -+ diet_ns_t_loc = 29, /* Location Information. */ -+ diet_ns_t_nxt = 30, /* Next domain (security). */ -+ diet_ns_t_eid = 31, /* Endpoint identifier. */ -+ diet_ns_t_nimloc = 32, /* Nimrod Locator. */ -+ diet_ns_t_srv = 33, /* Server Selection. */ -+ diet_ns_t_atma = 34, /* ATM Address */ -+ diet_ns_t_naptr = 35, /* Naming Authority PoinTeR */ -+ diet_ns_t_kx = 36, /* Key Exchange */ -+ diet_ns_t_cert = 37, /* Certification record */ -+ diet_ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ -+ diet_ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ -+ diet_ns_t_sink = 40, /* Kitchen sink (experimentatl) */ -+ diet_ns_t_opt = 41, /* EDNS0 option (meta-RR) */ -+ diet_ns_t_tsig = 250, /* Transaction signature. */ -+ diet_ns_t_ixfr = 251, /* Incremental zone transfer. */ -+ diet_ns_t_axfr = 252, /* Transfer zone of authority. */ -+ diet_ns_t_mailb = 253, /* Transfer mailbox records. */ -+ diet_ns_t_maila = 254, /* Transfer mail agent records. */ -+ diet_ns_t_any = 255, /* Wildcard match. */ -+ diet_ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ -+ diet_ns_t_max = 65536 -+}; -+ -+#define DIET_T_A diet_ns_t_a -+#define DIET_T_NS diet_ns_t_ns -+#define DIET_T_CNAME diet_ns_t_cname -+#define DIET_T_SOA diet_ns_t_soa -+#define DIET_T_PTR diet_ns_t_ptr -+#define DIET_T_MX diet_ns_t_mx -+#define DIET_T_TXT diet_ns_t_txt -+#define DIET_T_AAAA diet_ns_t_aaaa -+#define DIET_T_ANY diet_ns_t_any -+ -+/* -+ * Currently defined response codes. -+ */ -+enum diet_ns_rcode { -+ diet_ns_r_noerror = 0, /* No error occurred. */ -+ diet_ns_r_formerr = 1, /* Format error. */ -+ diet_ns_r_servfail = 2, /* Server failure. */ -+ diet_ns_r_nxdomain = 3, /* Name error. */ -+ diet_ns_r_notimpl = 4, /* Unimplemented. */ -+ diet_ns_r_refused = 5, /* Operation refused. */ -+ /* these are for BIND_UPDATE */ -+ diet_ns_r_yxdomain = 6, /* Name exists */ -+ diet_ns_r_yxrrset = 7, /* RRset exists */ -+ diet_ns_r_nxrrset = 8, /* RRset does not exist */ -+ diet_ns_r_notauth = 9, /* Not authoritative for zone */ -+ diet_ns_r_notzone = 10, /* Zone of record different from zone section */ -+ diet_ns_r_max = 11, -+ /* The following are TSIG extended errors */ -+ diet_ns_r_badsig = 16, -+ diet_ns_r_badkey = 17, -+ diet_ns_r_badtime = 18 -+}; -+ -+ -+ -+#define DIET_NOERROR diet_ns_r_noerror -+#define DIET_FORMERR diet_ns_r_formerr -+#define DIET_SERVFAIL diet_ns_r_servfail -+#define DIET_NXDOMAIN diet_ns_r_nxdomain -+#define DIET_NOTIMP diet_ns_r_notimpl -+#define DIET_REFUSED diet_ns_r_refused -+#define DIET_YXDOMAIN diet_ns_r_yxdomain -+#define DIET_YXRRSET diet_ns_r_yxrrset -+#define DIET_NXRRSET diet_ns_r_nxrrset -+#define DIET_NOTAUTH diet_ns_r_notauth -+#define DIET_NOTZONE diet_ns_r_notzone -+ -+ -+#define DIET_RES_RECURSE 0x00000040 /* recursion desired */ -+ -+extern struct diet_res_state _diet_res; -+extern int diet_h_errno; -+ -+int __dns_gethostbyx_r(const char* name, struct hostent* result, -+ char *buf, size_t buflen, -+ struct hostent **RESULT, int *h_errnop, int lookfor); -+int diet_gethostbyname2_r(const char* name, int AF, struct hostent* result, -+ char *buf, size_t buflen, -+ struct hostent **RESULT, int *h_errnop); -+int diet_res_query(const char *dname, int class, int type, unsigned char *answer, int anslen); -+int diet_res_mkquery(int op, const char *dname, int class, int type, char* data, -+ int datalen, const unsigned char* newrr, char* buf, int buflen); -+const char* diet_gai_strerror(int error); -+int diet_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); -+void diet_freeaddrinfo(struct addrinfo *res); -+int diet_res_init(void); -+int diet_dn_expand(const unsigned char *msg, const unsigned char *eomorig, const unsigned char *comp_dn, unsigned char *exp_dn, int length); -+ -+#endif -diff --git a/libres/dn_expand.c b/libres/dn_expand.c -new file mode 100644 -index 000000000..9eb458720 ---- /dev/null -+++ b/libres/dn_expand.c -@@ -0,0 +1,12 @@ -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+extern int __dns_decodename(const unsigned char *packet,unsigned int ofs,unsigned char *dest, -+ unsigned int maxlen,const unsigned char* behindpacket); -+ -+int diet_dn_expand(const unsigned char *msg, const unsigned char *eomorig, const unsigned char *comp_dn, unsigned char *exp_dn, int length) { -+ return __dns_decodename(msg,comp_dn-msg,exp_dn,length,eomorig)-(comp_dn-msg); -+} -diff --git a/libres/dnscruft.c b/libres/dnscruft.c -new file mode 100644 -index 000000000..142ffecd1 ---- /dev/null -+++ b/libres/dnscruft.c -@@ -0,0 +1,119 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+#ifdef __BIONIC__ -+#include -+#endif -+ -+ -+/* needs: -+ * _res -+ */ -+ -+int __dns_fd=-1; -+ -+/* the ad-hoc internal API from hell ;-) */ -+void __dns_make_fd(void); -+void __dns_make_fd6(void); -+void __dns_readstartfiles(void); -+int __dns_decodename(const unsigned char *packet,unsigned int offset,unsigned char *dest, -+ unsigned int maxlen,const unsigned char* behindpacket); -+ -+void __dns_make_fd(void) { -+ int tmp; -+ struct sockaddr_in si; -+ if (__dns_fd>=0) return; -+ tmp=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP); -+ if (tmp<0) return; -+ fcntl(tmp,F_SETFD,FD_CLOEXEC); -+ si.sin_family=AF_INET; -+ si.sin_port=0; -+ si.sin_addr.s_addr=INADDR_ANY; -+ if (bind(tmp,(struct sockaddr*)&si,sizeof(si))) return; -+ __dns_fd=tmp; -+} -+ -+static int parsesockaddr(const char* c,void* x) { -+ struct sockaddr_in to; -+ if (inet_aton(c,&to.sin_addr)) { -+ to.sin_port=htons(53); -+ to.sin_family=AF_INET; -+ memmove(x,&to,sizeof(struct sockaddr_in)); -+ return 1; -+ } -+ return 0; -+} -+ -+#define MAX_DNS_PROPERTIES 8 -+#define DNS_PROP_NAME_PREFIX "net.dns" -+void __dns_readstartfiles(void) { -+#ifdef __BIONIC__ -+ char propvalue[PROP_VALUE_MAX]; -+ char propname[PROP_NAME_MAX]; -+ int i; -+#endif -+ -+ if (_diet_res.nscount>0) -+ return; -+ -+ _diet_res.options=DIET_RES_RECURSE; -+ -+#ifdef __BIONIC__ -+ for(i = 1; i <= MAX_DNS_PROPERTIES; i++) { -+ snprintf(propname, sizeof(propname), "%s%d", DNS_PROP_NAME_PREFIX, i); -+ if(__system_property_get(propname, propvalue) < 1) { -+ break; -+ } -+ -+ if (parsesockaddr(propvalue,&_diet_res.nsaddr_list[_diet_res.nscount])) -+ if (_diet_res.nscount0&&*tmp; ) { -+ if (tmp>=behindpacket) return -1; -+ if ((*tmp>>6)==3) { /* goofy DNS decompression */ -+ unsigned int ofs=((unsigned int)(*tmp&0x3f)<<8)|*(tmp+1); -+ if (ofs>=(unsigned int)offset) return -1; /* RFC1035: "pointer to a _prior_ occurrance" */ -+ if (aftermax) return -1; -+ if (tmp+*tmp+1>=behindpacket) return -1; -+ for (duh=*tmp; duh>0; --duh) -+ *dest++=*++tmp; -+ *dest++='.'; ok=1; -+ ++tmp; -+ if (tmp>after) { after=tmp; if (!*tmp) ++after; } -+ } -+ } -+ if (ok) --dest; -+ *dest=0; -+ return after-packet; -+} -diff --git a/libres/dnscruft2.c b/libres/dnscruft2.c -new file mode 100644 -index 000000000..db9782f9e ---- /dev/null -+++ b/libres/dnscruft2.c -@@ -0,0 +1,132 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+/* needs: -+ * __dns_decodename -+ * res_query -+ */ -+ -+extern int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest, -+ unsigned int maxlen,unsigned char* behindpacket); -+ -+/* Oh boy, this interface sucks so badly, there are no words for it. -+ * Not one, not two, but _three_ error signalling methods! (*h_errnop -+ * nonzero? return value nonzero? *RESULT zero?) The glibc goons -+ * really outdid themselves with this one. */ -+int __dns_gethostbyx_r(const char* name, struct hostent* result, -+ char *buf, size_t buflen, -+ struct hostent **RESULT, int *h_errnop, int lookfor) { -+ int names,ips; -+ char *cur; -+ char *max; -+ char inpkg[1500]; -+ char* tmp; -+ int size; -+ -+ if (lookfor==1) { -+ result->h_addrtype=AF_INET; -+ result->h_length=4; -+ } else { -+ result->h_addrtype=AF_INET6; -+ result->h_length=16; -+ } -+ result->h_aliases=(char**)(buf+8*sizeof(char*)); -+ result->h_addr_list=(char**)buf; -+ result->h_aliases[0]=0; -+ -+ cur=buf+16*sizeof(char*); -+ max=buf+buflen; -+ names=ips=0; -+ -+ if ((size=diet_res_query(name,DIET_C_IN,lookfor,(unsigned char*)inpkg,512))<0) { -+invalidpacket: -+ *h_errnop=HOST_NOT_FOUND; -+ return -1; -+ } -+ { -+ tmp=inpkg+12; -+ { -+ unsigned char Name[257]; -+ unsigned short q=((unsigned short)inpkg[4]<<8)+inpkg[5]; -+ while (q>0) { -+ if (tmp>(char*)inpkg+size) goto invalidpacket; -+ while (*tmp) { tmp+=*tmp+1; if (tmp>(char*)inpkg+size) goto invalidpacket; } -+ tmp+=5; -+ --q; -+ } -+ if (tmp>inpkg+size) goto invalidpacket; -+ q=((unsigned short)inpkg[6]<<8)+inpkg[7]; -+ if (q<1) goto nodata; -+ while (q>0) { -+ int decofs=__dns_decodename((unsigned char*)inpkg,(size_t)(tmp-(char*)inpkg),Name,256,(unsigned char*)inpkg+size); -+ if (decofs<0) break; -+ tmp=inpkg+decofs; -+ --q; -+ if (tmp[0]!=0 || tmp[1]!=lookfor || /* TYPE != A */ -+ tmp[2]!=0 || tmp[3]!=1) { /* CLASS != IN */ -+ if (tmp[1]==5) { /* CNAME */ -+ tmp+=10; -+ decofs=__dns_decodename((unsigned char*)inpkg,(size_t)(tmp-(char*)inpkg),Name,256,(unsigned char*)inpkg+size); -+ if (decofs<0) break; -+ tmp=inpkg+decofs; -+ } else -+ break; -+ continue; -+ } -+ tmp+=10; /* skip type, class, TTL and length */ -+ { -+ int slen; -+ if (lookfor==1 || lookfor==28) /* A or AAAA*/ { -+ slen=strlen((char*)Name); -+ if (cur+slen+8+(lookfor==28?12:0)>=max) { *h_errnop=NO_RECOVERY; return -1; } -+ } else { -+ if (lookfor==12) /* PTR */ { -+ decofs=__dns_decodename((unsigned char*)inpkg,(size_t)(tmp-(char*)inpkg),Name,256,(unsigned char*)inpkg+size); -+ if (decofs<0) break; -+ tmp=inpkg+decofs; -+ } -+ slen=strlen((char*)Name); -+ } -+ strcpy(cur,(char*)Name); -+ if (names==0) -+ result->h_name=cur; -+ else -+ result->h_aliases[names-1]=cur; -+ result->h_aliases[names]=0; -+ if (names<8) ++names; -+/* cur+=slen+1; */ -+ cur+=(slen|3)+1; -+ result->h_addr_list[ips++] = cur; -+ if (lookfor==1) /* A */ { -+ memcpy(cur,tmp,4); -+ cur+=4; tmp+=4; -+ result->h_addr_list[ips]=0; -+ } else if (lookfor==28) /* AAAA */ { -+ memcpy(cur,tmp,16); -+ cur+=16; tmp+=16; -+ result->h_addr_list[ips]=0; -+ } -+ } -+/* puts(Name); */ -+ } -+ } -+ } -+ if (!names) { -+nodata: -+ *h_errnop=NO_DATA; -+ return -1; -+ } -+ *h_errnop=0; -+ *RESULT=result; -+ return 0; -+} -diff --git a/libres/dnscruft3.c b/libres/dnscruft3.c -new file mode 100644 -index 000000000..379dc8b80 ---- /dev/null -+++ b/libres/dnscruft3.c -@@ -0,0 +1,6 @@ -+#include -+#include -+#include -+#include "dietdns.h" -+ -+struct diet_res_state _diet_res; /* don't ask. */ -diff --git a/libres/freeaddrinfo.c b/libres/freeaddrinfo.c -new file mode 100644 -index 000000000..f525d2cd1 ---- /dev/null -+++ b/libres/freeaddrinfo.c -@@ -0,0 +1,14 @@ -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+void diet_freeaddrinfo(struct addrinfo *res) { -+ while (res) { -+ struct addrinfo *duh; -+ duh=res; -+ res=res->ai_next; -+ free(duh); -+ } -+} -diff --git a/libres/gai_strerror.c b/libres/gai_strerror.c -new file mode 100644 -index 000000000..311777ef9 ---- /dev/null -+++ b/libres/gai_strerror.c -@@ -0,0 +1,14 @@ -+#include -+#include -+ -+const char* diet_gai_strerror(int error) { -+ switch (error) { -+ case EAI_FAMILY: return "family not supported"; -+ case EAI_SOCKTYPE: return "socket type not supported"; -+ case EAI_NONAME: return "unknown host"; -+ case EAI_SERVICE: return "unknown service"; -+ case EAI_MEMORY: return "memory allocation failure"; -+ case EAI_AGAIN: return "temporary failure"; -+ } -+ return "DNS error. Sorry."; -+} -diff --git a/libres/getaddrinfo.c b/libres/getaddrinfo.c -new file mode 100644 -index 000000000..3c6f7ee81 ---- /dev/null -+++ b/libres/getaddrinfo.c -@@ -0,0 +1,137 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+/* XXX TODO FIXME */ -+ -+/* needs: -+ * gethostbyname2_r -+ */ -+ -+int diet_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { -+ struct addrinfo **tmp; -+ int family; -+ tmp=res; *res=0; -+ if (hints) { -+ if (hints->ai_family && hints->ai_family != PF_INET6 && hints->ai_family != PF_INET) return EAI_FAMILY; -+ if (hints->ai_socktype && hints->ai_socktype != SOCK_STREAM && hints->ai_socktype != SOCK_DGRAM) return EAI_SOCKTYPE; -+ } -+ for (family=PF_INET6; ; family=PF_INET) { -+ if (!hints || hints->ai_family==family || hints->ai_family==AF_UNSPEC) { /* IPv6 addresses are OK */ -+ struct hostent h; -+ struct hostent *H; -+ int herrno=0; -+ char buf[4096]; -+ int lookupok=0, i; -+ char* interface; -+ h.h_addr_list=(char**)buf+16; -+ h.h_addr_list[1]=0; -+ if (node) { -+ if ((interface=strchr(node,'%'))) ++interface; -+ if (family==PF_INET6 && inet_pton(AF_INET,node,buf)) continue; -+ if (inet_pton(family,node,buf)>0) { -+ h.h_name=(char*)node; -+ h.h_addr_list[0]=buf; -+ lookupok=1; -+ } else if ((!hints || !(hints->ai_flags&AI_NUMERICHOST)) && -+ !diet_gethostbyname2_r(node,family,&h,buf,4096,&H,&herrno)) { -+ lookupok=1; -+ } else { -+ if (herrno==TRY_AGAIN) { diet_freeaddrinfo(*res); return EAI_AGAIN; } -+ } -+ } else { -+ h.h_name=0; -+ h.h_addr_list[0]=buf; -+ interface=0; -+ memset(buf,0,16); -+ if (!hints || !(hints->ai_flags&AI_PASSIVE)) { -+ if (family==AF_INET) { -+ buf[0]=127; buf[3]=1; -+ } else -+ buf[15]=1; -+ } -+ lookupok=1; -+ } -+ if (lookupok) { -+ -+ for (i=0; h.h_addr_list[i]; ++i) { -+ struct ai_v6 { -+ struct addrinfo ai; -+ union { -+ struct sockaddr_in6 ip6; -+ struct sockaddr_in ip4; -+ } ip; -+ char name[1]; -+ } *foo; -+ unsigned short port; -+ int len; -+ -+ len=sizeof(struct ai_v6)+(h.h_name?strlen(h.h_name):0); -+ -+ if (!(foo=malloc(len))) goto error; -+ foo->ai.ai_next=0; -+ foo->ai.ai_addrlen=family==PF_INET6?sizeof(struct sockaddr_in6):sizeof(struct sockaddr_in); -+ foo->ai.ai_addr=(struct sockaddr*)&foo->ip; -+ if (family==PF_INET6) { -+ memset(&foo->ip,0,sizeof(foo->ip)); -+ memmove(&foo->ip.ip6.sin6_addr,h.h_addr_list[i],16); -+ if (interface) foo->ip.ip6.sin6_scope_id=if_nametoindex(interface); -+ } else { -+ memmove(&foo->ip.ip4.sin_addr,h.h_addr_list[i],4); -+ } -+ foo->ip.ip6.sin6_family=foo->ai.ai_family=family; -+ if (h.h_name) { -+ foo->ai.ai_canonname=foo->name; -+ memmove(foo->name,h.h_name,strlen(h.h_name)+1); -+ } else -+ foo->ai.ai_canonname=0; -+ -+ for (foo->ai.ai_socktype=SOCK_STREAM; ; foo->ai.ai_socktype=SOCK_DGRAM) { -+ char* type,* x; -+ if (foo->ai.ai_socktype==SOCK_STREAM) { /* TCP */ -+ if (hints && hints->ai_socktype==SOCK_DGRAM) continue; -+ foo->ai.ai_protocol=IPPROTO_TCP; -+ type="tcp"; -+ } else { /* UDP */ -+ if (hints && hints->ai_socktype==SOCK_STREAM) break; -+ foo->ai.ai_protocol=IPPROTO_UDP; -+ type="udp"; -+ } -+ port=htons(strtol(service?service:"0",&x,0)); -+ if (*x) { /* service is not numeric :-( */ -+ free(foo); -+ /* no getservbyname on android */ -+ diet_freeaddrinfo(*res); -+ return EAI_SERVICE; -+ } -+ if (family==PF_INET6) -+ foo->ip.ip6.sin6_port=port; -+ else -+ foo->ip.ip4.sin_port=port; -+ if (!*tmp) *tmp=&(foo->ai); else (*tmp)->ai_next=&(foo->ai); -+ if (!(foo=malloc(len))) goto error; -+ memmove(foo,*tmp,len); -+ tmp=&(*tmp)->ai_next; -+ foo->ai.ai_addr=(struct sockaddr*)&foo->ip; -+ if (foo->ai.ai_canonname) -+ foo->ai.ai_canonname=foo->name; -+ if (foo->ai.ai_socktype==SOCK_DGRAM) break; -+ } -+ free(foo); -+ } -+ } -+ } -+ if (family==PF_INET) break; -+ } -+ if (*res==0) return EAI_NONAME; /* kludge kludge... */ -+ return 0; -+error: -+ diet_freeaddrinfo(*res); -+ return EAI_MEMORY; -+} -diff --git a/libres/gethostbyname2_r.c b/libres/gethostbyname2_r.c -new file mode 100644 -index 000000000..2558e5d5f ---- /dev/null -+++ b/libres/gethostbyname2_r.c -@@ -0,0 +1,35 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+/* needs: -+ * __dns_gethostbyx_r -+ */ -+ -+/* Oh boy, this interface sucks so badly, there are no words for it. -+ * Not one, not two, but _three_ error signalling methods! (*h_errnop -+ * nonzero? return value nonzero? *RESULT zero?) The glibc goons -+ * really outdid themselves with this one. */ -+int diet_gethostbyname2_r(const char* name, int AF, struct hostent* result, -+ char *buf, size_t buflen, -+ struct hostent **RESULT, int *h_errnop) { -+ size_t L=strlen(name); -+ int lookfor=0; -+ switch (AF) { -+ case AF_INET: lookfor=1; break; -+ case AF_INET6: lookfor=28; break; -+ default: *h_errnop=EINVAL; return 1; -+ } -+ result->h_name=buf; -+ if (buflen -+#include -+#include -+#include "dietdns.h" -+ -+extern void __dns_readstartfiles(void); -+ -+int diet_res_init(void) { -+ _diet_res.nscount=0; -+ __dns_readstartfiles(); -+ return 0; -+} -diff --git a/libres/res_mkquery.c b/libres/res_mkquery.c -new file mode 100644 -index 000000000..a8cece631 ---- /dev/null -+++ b/libres/res_mkquery.c -@@ -0,0 +1,85 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+/* needs: -+ * _res -+ */ -+ -+static char dnspacket[]="\xfe\xfe\001\000\000\001\000\000\000\000\000\000"; -+ -+/* -+ 1 1 1 1 1 1 -+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 -+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ | ID | -+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ |QR| Opcode |AA|TC|RD|RA| Z | RCODE | -+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ | QDCOUNT | -+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ | ANCOUNT | -+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ | NSCOUNT | -+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+ | ARCOUNT | -+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ -+*/ -+ -+extern void __dns_make_fd(void); -+extern int __dns_fd; -+ -+extern int __dns_servers; -+extern struct sockaddr __dns_server_ips[]; -+ -+extern void __dns_readstartfiles(void); -+ -+int diet_res_mkquery(int op, const char *dname, int class, int type, char* data, -+ int datalen, const unsigned char* newrr, char* buf, int buflen) { -+ unsigned char packet[512]; -+ unsigned long len; -+ -+ memcpy(packet,dnspacket,12); -+ len=rand(); -+ packet[0]=len; -+ packet[1]=len>>8; -+ len=0; -+ if ((_diet_res.options&DIET_RES_RECURSE)==0) packet[2]=0; -+ { -+ unsigned char* x; -+ const char* y,* tmp; -+ x=packet+12; y=dname; -+ while (*y) { -+ while (*y=='.') ++y; -+ for (tmp=y; *tmp && *tmp!='.'; ++tmp) ; -+ if (tmp-y > 63) return -1; -+ *x=tmp-y; -+ if (!(tmp-y)) break; -+ if ((len+=*x+1) > 254) return -1; -+ ++x; -+// if (x>=packet+510-(tmp-y)) { return -1; } -+ memmove(x,y,tmp-y); -+ x+=tmp-y; -+ if (!*tmp) { -+ *x=0; -+ break; -+ } -+ y=tmp; -+ } -+ *++x= 0; *++x= type; /* A */ -+ *++x= 0; *++x= class; /* IN */ -+ ++x; -+ if (x-packet>buflen) return -1; -+ memmove(buf,packet,x-packet); -+ return x-packet; -+ } -+} -diff --git a/libres/res_query.c b/libres/res_query.c -new file mode 100644 -index 000000000..19898b75c ---- /dev/null -+++ b/libres/res_query.c -@@ -0,0 +1,81 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+/* needs: -+ * __dns_fd -+ * __dns_make_fd -+ * __dns_readstartfiles -+ * h_errno -+ * diet_res_mkquery -+ * _res -+ */ -+ -+extern void __dns_make_fd(void); -+extern int __dns_fd; -+ -+extern void __dns_readstartfiles(void); -+ -+int diet_res_query(const char *dname, int class, int type, unsigned char *answer, int anslen) { -+ unsigned char packet[512]; -+ int size; -+ struct pollfd duh[2]; -+ __dns_make_fd(); -+ -+ __dns_readstartfiles(); -+ if ((size=diet_res_mkquery(DIET_QUERY,dname,class,type,0,0,0,(char*)packet,512))<0) { diet_h_errno=NO_RECOVERY; return -1; } -+ { -+ { -+ int i; /* current server */ -+ int j; /* timeout count down */ -+ struct timeval last,now; -+ -+ i=0; -+ duh[0].events=POLLIN; -+ duh[0].fd=0; -+ last.tv_sec=0; -+ for (j=20; j>0; --j) { -+ gettimeofday(&now,0); -+ if (now.tv_sec-last.tv_sec>10) { -+ duh[0].fd=__dns_fd; -+ sendto(__dns_fd,packet,size,0,(struct sockaddr*)&(_diet_res.nsaddr_list[i]),sizeof(struct sockaddr)); -+ last=now; -+ } -+ if (++i >= _diet_res.nscount) i=0; -+ if (poll(duh,1,1000) == 1) { -+ /* read and parse answer */ -+ unsigned char inpkg[1500]; -+ int len=read(duh[0].fd,inpkg,sizeof(inpkg)); -+ /* header, question, answer, authority, additional */ -+ if (inpkg[0]!=packet[0] || inpkg[1]!=packet[1]) continue; /* wrong ID */ -+ if ((inpkg[2]&0xf9) != (_diet_res.options&DIET_RES_RECURSE?0x81:0x80)) continue; /* not answer */ -+ if ((inpkg[3]&0x0f) != 0) { -+ diet_h_errno=HOST_NOT_FOUND; -+ return -1; -+ } /* error */ -+ if (len>anslen) { -+ diet_h_errno=NO_RECOVERY; -+ return -1; -+ } -+ memcpy(answer,inpkg,len); -+ return len; -+ } -+/*kaputt:*/ -+ } -+ } -+ } -+ diet_h_errno=TRY_AGAIN; -+ return -1; -+} -diff --git a/libres/test.c b/libres/test.c -new file mode 100644 -index 000000000..45095d81d ---- /dev/null -+++ b/libres/test.c -@@ -0,0 +1,105 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include "dietdns.h" -+ -+union common_sockaddr { -+ struct sockaddr sa; -+ struct sockaddr_in sin; -+ struct sockaddr_in6 sin6; -+}; -+typedef union common_sockaddr sockaddr_any; -+ -+static int getaddr (const char *name, sockaddr_any *addr, int af) { -+ int ret; -+ struct addrinfo hints, *ai, *res = NULL; -+ -+ memset (&hints, 0, sizeof (hints)); -+ hints.ai_family = af; -+ hints.ai_socktype = SOCK_DGRAM; -+ hints.ai_flags = AI_ADDRCONFIG; -+ -+ ret = diet_getaddrinfo (name, NULL, &hints, &res); -+ if (ret) { -+ fprintf (stderr, "%s: %s\n", name, diet_gai_strerror (ret)); -+ return -1; -+ } -+ -+ for (ai = res; ai; ai = ai->ai_next) { -+ if (ai->ai_family == af) break; -+ } -+ if (!ai) ai = res; /* anything... */ -+ -+ if (ai->ai_addrlen > sizeof (*addr)) -+ return -1; /* paranoia */ -+ memcpy (addr, ai->ai_addr, ai->ai_addrlen); -+ -+ if(res != NULL) -+ diet_freeaddrinfo (res); -+ -+ return 0; -+} -+ -+static void printaddr(sockaddr_any *addr) { -+ char addr_str[INET6_ADDRSTRLEN]; -+ -+ if(addr->sa.sa_family == AF_INET) { -+ printf("family = AF_INET\n"); -+ if(inet_ntop(addr->sin.sin_family, &addr->sin.sin_addr, (char *)&addr_str, sizeof(addr_str)) == NULL) { -+ perror("inet_ntop failed"); -+ return; -+ } -+ printf("addr = %s\n", addr_str); -+ } else if(addr->sa.sa_family == AF_INET6) { -+ printf("family = AF_INET6\n"); -+ if(inet_ntop(addr->sin6.sin6_family, &addr->sin6.sin6_addr, (char *)&addr_str, sizeof(addr_str)) == NULL) { -+ perror("inet_ntop failed"); -+ return; -+ } -+ printf("addr = %s\n", addr_str); -+ } else { -+ printf("unknown family = %d\n",addr->sa.sa_family); -+ } -+} -+ -+int main() { -+ sockaddr_any dst_addr = {{ 0, }, }; -+ struct sockaddr_in lsa_u; -+ -+ if (getaddr("www.datapipe.net", &dst_addr, AF_INET) < 0) { -+ fprintf(stderr, "getaddr failed\n"); -+ } else { -+ printaddr(&dst_addr); -+ } -+ -+ if (getaddr("www.datapipe.net", &dst_addr, AF_INET6) < 0) { -+ fprintf(stderr, "getaddr failed\n"); -+ } else { -+ printaddr(&dst_addr); -+ } -+ -+ inet_aton("127.0.0.1",&lsa_u.sin_addr); -+ lsa_u.sin_port=htons(53); -+ lsa_u.sin_family=AF_INET; -+ -+ _diet_res.nscount = 1; -+ _diet_res.nsaddr_list[0] = lsa_u; -+ -+ if (getaddr("www.datapipe.net", &dst_addr, AF_INET6) < 0) { -+ fprintf(stderr, "getaddr failed\n"); -+ } else { -+ printaddr(&dst_addr); -+ } -+ -+ return 0; -+} -diff --git a/networking/nslookup.c b/networking/nslookup.c -index 6da97baf4..8c20d8364 100644 ---- a/networking/nslookup.c -+++ b/networking/nslookup.c -@@ -36,8 +36,9 @@ - - #include - #include /* for IFNAMSIZ */ --//#include --//#include -+#include -+#include -+#include "../libres/dietdns.h" - #include "libbb.h" - #include "common_bufsiz.h" - -@@ -106,7 +107,7 @@ static int print_host(const char *hostname, const char *header) - * for each possible socket type (tcp,udp,raw...): */ - hint.ai_socktype = SOCK_STREAM; - // hint.ai_flags = AI_CANONNAME; -- rc = getaddrinfo(hostname, NULL /*service*/, &hint, &result); -+ rc = diet_getaddrinfo(hostname, NULL /*service*/, &hint, &result); - - if (rc == 0) { - struct addrinfo *cur = result; -@@ -137,7 +138,7 @@ static int print_host(const char *hostname, const char *header) - #endif - } - if (ENABLE_FEATURE_CLEAN_UP && result) -- freeaddrinfo(result); -+ diet_freeaddrinfo(result); - return (rc != 0); - } - -@@ -147,11 +148,11 @@ static void server_print(void) - char *server; - struct sockaddr *sa; - --#if ENABLE_FEATURE_IPV6 -- sa = (struct sockaddr*)_res._u._ext.nsaddrs[0]; -+#if 0 -+ sa = (struct sockaddr*)_diet_res._u._ext.nsaddrs[0]; - if (!sa) - #endif -- sa = (struct sockaddr*)&_res.nsaddr_list[0]; -+ sa = (struct sockaddr*)&_diet_res.nsaddr_list[0]; - server = xmalloc_sockaddr2dotted_noport(sa); - - print_host(server, "Server:"); -@@ -173,11 +174,11 @@ static void set_default_dns(const char *server) - lsa = xhost2sockaddr(server, 53); - - if (lsa->u.sa.sa_family == AF_INET) { -- _res.nscount = 1; -+ _diet_res.nscount = 1; - /* struct copy */ -- _res.nsaddr_list[0] = lsa->u.sin; -+ _diet_res.nsaddr_list[0] = lsa->u.sin; - } --#if ENABLE_FEATURE_IPV6 -+#if 0 - /* Hoped libc can cope with IPv4 address there too. - * No such luck, glibc 2.4 segfaults even with IPv6, - * maybe I misunderstand how to make glibc use IPv6 addr? -@@ -186,9 +187,9 @@ static void set_default_dns(const char *server) - // glibc neither SEGVs nor sends any dgrams with this - // (strace shows no socket ops): - //_res.nscount = 0; -- _res._u._ext.nscount = 1; -+ _diet_res._u._ext.nscount = 1; - /* store a pointer to part of malloc'ed lsa */ -- _res._u._ext.nsaddrs[0] = &lsa->u.sin6; -+ _diet_res._u._ext.nsaddrs[0] = &lsa->u.sin6; - /* must not free(lsa)! */ - } - #endif -@@ -207,7 +208,7 @@ int nslookup_main(int argc, char **argv) - - /* initialize DNS structure _res used in printing the default - * name server and in the explicit name server option feature. */ -- res_init(); -+ diet_res_init(); - /* rfc2133 says this enables IPv6 lookups */ - /* (but it also says "may be enabled in /etc/resolv.conf") */ - /*_res.options |= RES_USE_INET6;*/ --- -2.45.2 - diff --git a/patches/0025-hack-use-dietlibc-s-resolver-to-avoid-static-compili.patch b/patches/0025-hack-use-dietlibc-s-resolver-to-avoid-static-compili.patch deleted file mode 100644 index 7387563..0000000 --- a/patches/0025-hack-use-dietlibc-s-resolver-to-avoid-static-compili.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 4b30a324c4f5b6f57f0a6c13741b251b445ee72a Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Wed, 30 Oct 2019 02:47:24 -0300 -Subject: [PATCH 25/35] hack: use dietlibc's resolver to avoid static - compiliation issues with bionic's getaddrinfo() returning only null instead - of opening the expected connection to /dev/socket/dnsproxyd - ---- - libbb/xconnect.c | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/libbb/xconnect.c b/libbb/xconnect.c -index 0e0b247b8..2116c0b6f 100644 ---- a/libbb/xconnect.c -+++ b/libbb/xconnect.c -@@ -11,6 +11,8 @@ - #include - #include - #include -+#include -+#include "../libres/dietdns.h" - #if ENABLE_IFPLUGD || ENABLE_FEATURE_MDEV_DAEMON || ENABLE_UEVENT - # include - #endif -@@ -277,7 +279,7 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;) - * for each possible socket type (tcp,udp,raw...): */ - hint.ai_socktype = SOCK_STREAM; - hint.ai_flags = ai_flags & ~DIE_ON_ERROR; -- rc = getaddrinfo(host, NULL, &hint, &result); -+ rc = diet_getaddrinfo(host, NULL, &hint, &result); /* hack to use dietlibc's resolver to work around static compile issue */ - if (rc || !result) { - bb_error_msg("bad address '%s'", org_host); - if (ai_flags & DIE_ON_ERROR) -@@ -304,7 +306,7 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;) - set_nport(&r->u.sa, htons(port)); - ret: - if (result) -- freeaddrinfo(result); -+ diet_freeaddrinfo(result); /* hack to use dietlibc's resolver to work around static compile issue */ - return r; - } - #if !ENABLE_FEATURE_IPV6 --- -2.45.2 - diff --git a/patches/0026-dietlibc-dnscruft-try-to-get-dns-server-via-command-.patch b/patches/0026-dietlibc-dnscruft-try-to-get-dns-server-via-command-.patch deleted file mode 100644 index df64567..0000000 --- a/patches/0026-dietlibc-dnscruft-try-to-get-dns-server-via-command-.patch +++ /dev/null @@ -1,50 +0,0 @@ -From d882a3fe4415965688b4e450d8c5191cd87817ee Mon Sep 17 00:00:00 2001 -From: Chris Renshaw -Date: Mon, 3 Jul 2017 03:17:06 -0300 -Subject: [PATCH 26/35] dietlibc/dnscruft: try to get dns server via command if - __sys_property_get fails - -- bionic libc's property_get and __sys_property_get fail for statically compiled binaries -- fallback to a default known dns server if all else fails ---- - libres/dnscruft.c | 17 ++++++++++++++++- - 1 file changed, 16 insertions(+), 1 deletion(-) - -diff --git a/libres/dnscruft.c b/libres/dnscruft.c -index 142ffecd1..7804765b9 100644 ---- a/libres/dnscruft.c -+++ b/libres/dnscruft.c -@@ -61,6 +61,9 @@ void __dns_readstartfiles(void) { - #ifdef __BIONIC__ - char propvalue[PROP_VALUE_MAX]; - char propname[PROP_NAME_MAX]; -+ char propcmd[PROP_NAME_MAX+8]; -+ char pbuf[256]; -+ FILE *fp; - int i; - #endif - -@@ -73,7 +76,19 @@ void __dns_readstartfiles(void) { - for(i = 1; i <= MAX_DNS_PROPERTIES; i++) { - snprintf(propname, sizeof(propname), "%s%d", DNS_PROP_NAME_PREFIX, i); - if(__system_property_get(propname, propvalue) < 1) { -- break; -+ /* attempt to get the property via command instead since the call to Bionic libc failed */ -+ snprintf(propcmd, sizeof(propcmd), "getprop %s", propname); -+ if((fp = popen(propcmd, "r"))) { -+ if((fgets(pbuf, sizeof(pbuf)-1, fp) != NULL) && (strlen(pbuf) > 0)) { -+ if (pbuf[strlen(pbuf)-1] == '\n') -+ pbuf[strlen(pbuf)-1] = '\0'; /* strip trailing newline */ -+ strncpy(propvalue, pbuf, sizeof(propvalue)); -+ } -+ } -+ pclose(fp); -+ memset(&propname[0], 0, sizeof(propname)); /* clear propname to avoid unpredictable behavior */ -+ if(strlen(propvalue) < 1) -+ strcpy(propvalue, "8.8.8.8"); /* use a fallback nameserver since we still fail to get the property correctly */ - } - - if (parsesockaddr(propvalue,&_diet_res.nsaddr_list[_diet_res.nscount])) --- -2.45.2 - diff --git a/patches/0030-Fix-incorrect-assumptions-about-NDK.patch b/patches/0030-Fix-incorrect-assumptions-about-NDK.patch deleted file mode 100644 index 0d0b47c..0000000 --- a/patches/0030-Fix-incorrect-assumptions-about-NDK.patch +++ /dev/null @@ -1,55 +0,0 @@ -From 07edcd9e82a33f32070e4f124bdb634b50269b7a Mon Sep 17 00:00:00 2001 -From: topjohnwu -Date: Fri, 3 Apr 2020 02:09:55 -0700 -Subject: [PATCH 30/35] Fix incorrect assumptions about NDK - ---- - include/platform.h | 4 +++- - libbb/missing_syscalls.c | 15 --------------- - 2 files changed, 3 insertions(+), 16 deletions(-) - -diff --git a/include/platform.h b/include/platform.h -index 57f0ef57d..69687eca7 100644 ---- a/include/platform.h -+++ b/include/platform.h -@@ -549,8 +549,10 @@ typedef unsigned smalluint; - # if __ANDROID_API__ >= 21 - # undef HAVE_WAIT3 - # endif -+# if __ANDROID_API__ < 24 -+# undef HAVE_STRCHRNUL -+# endif - # undef HAVE_MEMPCPY --# undef HAVE_STRCHRNUL - # undef HAVE_STRVERSCMP - # undef HAVE_UNLOCKED_LINE_OPS - # undef HAVE_NET_ETHERNET_H -diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c -index f02e8d14c..a6db67da9 100644 ---- a/libbb/missing_syscalls.c -+++ b/libbb/missing_syscalls.c -@@ -54,21 +54,6 @@ - #if defined(ANDROID) || defined(__ANDROID__) - /*# include - for struct timex, but may collide with */ - # include --pid_t getsid(pid_t pid) --{ -- return syscall(__NR_getsid, pid); --} -- --int sethostname(const char *name, size_t len) --{ -- return syscall(__NR_sethostname, name, len); --} -- --struct timex; --int adjtimex(struct timex *buf) --{ -- return syscall(__NR_adjtimex, buf); --} - - int pivot_root(const char *new_root, const char *put_old) - { --- -2.45.2 - diff --git a/patches/0035-Allow-variable-page-size-on-x64.patch b/patches/0035-Allow-variable-page-size-on-x64.patch deleted file mode 100644 index e425719..0000000 --- a/patches/0035-Allow-variable-page-size-on-x64.patch +++ /dev/null @@ -1,25 +0,0 @@ -From c032074c4576b20d1dc7c38b0d187529d23c1ac9 Mon Sep 17 00:00:00 2001 -From: topjohnwu -Date: Fri, 21 Jun 2024 03:09:47 -0700 -Subject: [PATCH 35/35] Allow variable page size on x64 - ---- - include/libbb.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/include/libbb.h b/include/libbb.h -index 112e45197..401a8ec9a 100644 ---- a/include/libbb.h -+++ b/include/libbb.h -@@ -435,7 +435,7 @@ void *mmap_read(int fd, size_t size) FAST_FUNC; - void *mmap_anon(size_t size) FAST_FUNC; - void *xmmap_anon(size_t size) FAST_FUNC; - --#if defined(__x86_64__) || defined(i386) -+#if defined(i386) /* only 32bit, x64 has emulated variable page size */ - # define BB_ARCH_FIXED_PAGESIZE 4096 - #elif defined(__arm__) /* only 32bit, 64bit ARM has variable page size */ - # define BB_ARCH_FIXED_PAGESIZE 4096 --- -2.45.2 -