From 7fdb764e2e12119949cc17046d5ad4a13a9be4c6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 3 Jul 2017 02:33:08 +0200 Subject: scripts/randomtest: update things which can't be tested on uclibc Signed-off-by: Denys Vlasenko --- scripts/randomtest | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'scripts') diff --git a/scripts/randomtest b/scripts/randomtest index 287f1c771..1809838a4 100755 --- a/scripts/randomtest +++ b/scripts/randomtest @@ -82,6 +82,9 @@ if test x"$LIBC" = x"uclibc"; then | grep -v CONFIG_BLKDISCARD \ | grep -v CONFIG_NSENTER \ | grep -v CONFIG_UNSHARE \ + | grep -v CONFIG_FALLOCATE \ + | grep -v CONFIG_UDHCPC6 \ + | grep -v CONFIG_ASH_INTERNAL_GLOB \ >.config.new mv .config.new .config echo 'CONFIG_STATIC=y' >>.config @@ -96,6 +99,9 @@ if test x"$LIBC" = x"uclibc"; then echo '# CONFIG_BLKDISCARD is not set' >>.config echo '# CONFIG_NSENTER is not set' >>.config echo '# CONFIG_UNSHARE is not set' >>.config + echo '# CONFIG_FALLOCATE is not set' >>.config + echo '# CONFIG_UDHCPC6 is not set' >>.config + echo 'CONFIG_ASH_INTERNAL_GLOB=y' >>.config fi # If STATIC, remove some things. -- cgit v1.2.3-55-g6feb From d4e4fdb5ce5ccc067b3d35d877f7a7d978869517 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 3 Jul 2017 21:31:16 +0200 Subject: fixes for bugs found by make_single_applets.sh Signed-off-by: Denys Vlasenko --- archival/bbunzip.c | 11 ++++++++--- include/libbb.h | 2 ++ libbb/appletlib.c | 20 ++++++++++++++++---- libbb/getopt32.c | 4 +--- libbb/vfork_daemon_rexec.c | 3 ++- networking/inetd.c | 17 ++++++++++------- scripts/randomtest.loop | 26 ++++++++++++++++++++++++++ shell/hush.c | 26 ++++++-------------------- shell/shell_common.c | 4 +--- util-linux/fdisk.c | 3 +++ 10 files changed, 75 insertions(+), 41 deletions(-) (limited to 'scripts') diff --git a/archival/bbunzip.c b/archival/bbunzip.c index c60f6e6df..f7a7ab354 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -7,14 +7,19 @@ #include "libbb.h" #include "bb_archive.h" +//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o +//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o +//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o +//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o + /* lzop_main() uses bbunpack(), need this: */ //kbuild:lib-$(CONFIG_LZOP) += bbunzip.o //kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o //kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o /* bzip2_main() too: */ -//kbuild:lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += bbunzip.o +//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o /* gzip_main() too: */ -//kbuild:lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += bbunzip.o +//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o /* Note: must be kept in sync with archival/lzop.c */ enum { @@ -443,7 +448,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) //applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) // APPLET_ODDNAME:name main location suid_type help //applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) -#if ENABLE_FEATURE_BZIP2_DECOMPRESS +#if ENABLE_FEATURE_BZIP2_DECOMPRESS || ENABLE_BUNZIP2 int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int bunzip2_main(int argc UNUSED_PARAM, char **argv) { diff --git a/include/libbb.h b/include/libbb.h index 9b72c97be..557978e66 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -778,6 +778,8 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags, uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC; +/* 0 if argv[0] is NULL: */ +unsigned string_array_len(char **argv) FAST_FUNC; void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 7f0d62060..2dea2b43a 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -78,6 +78,17 @@ #endif +unsigned FAST_FUNC string_array_len(char **argv) +{ + char **start = argv; + + while (*argv) + argv++; + + return argv - start; +} + + #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; #else @@ -868,10 +879,7 @@ static int busybox_main(char **argv) # if NUM_APPLETS > 0 void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) { - int argc = 1; - - while (argv[argc]) - argc++; + int argc = string_array_len(argv); /* Reinit some shared global data */ xfunc_error_retval = EXIT_FAILURE; @@ -993,7 +1001,11 @@ int main(int argc UNUSED_PARAM, char **argv) } /* applet_names in this case is just "applet\0\0" */ lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); +# if ENABLE_BUILD_LIBBUSYBOX + return SINGLE_APPLET_MAIN(string_array_len(argv), argv); +# else return SINGLE_APPLET_MAIN(argc, argv); +# endif #elif !ENABLE_BUSYBOX && NUM_APPLETS == 0 diff --git a/libbb/getopt32.c b/libbb/getopt32.c index b87b83538..80f4cc060 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -379,9 +379,7 @@ getopt32(char **argv, const char *applet_opts, ...) int spec_flgs = 0; /* skip 0: some applets cheat: they do not actually HAVE argv[0] */ - argc = 1; - while (argv[argc]) - argc++; + argc = 1 + string_array_len(argv + 1); va_start(p, applet_opts); diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index fd481bf6e..2695f99ee 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c @@ -16,6 +16,7 @@ */ #include "busybox.h" /* uses applet tables */ +#include "NUM_APPLETS.h" /* This does a fork/exec in one call, using vfork(). Returns PID of new child, * -1 for failure. Runs argv[0], searching path if that has no / in it. */ @@ -156,7 +157,7 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv) int FAST_FUNC spawn_and_wait(char **argv) { int rc; -#if ENABLE_FEATURE_PREFER_APPLETS +#if ENABLE_FEATURE_PREFER_APPLETS && (NUM_APPLETS > 1) int a = find_applet_by_name(argv[0]); if (a >= 0) { diff --git a/networking/inetd.c b/networking/inetd.c index 01e659f13..39169a935 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -1513,8 +1513,11 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) } /* for (;;) */ } -#if !BB_MMU +#if ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_ECHO \ + || ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD +# if !BB_MMU static const char *const cat_args[] = { "cat", NULL }; +# endif #endif /* @@ -1525,14 +1528,14 @@ static const char *const cat_args[] = { "cat", NULL }; /* ARGSUSED */ static void FAST_FUNC echo_stream(int s, servtab_t *sep UNUSED_PARAM) { -#if BB_MMU +# if BB_MMU while (1) { ssize_t sz = safe_read(s, line, LINE_SIZE); if (sz <= 0) break; xwrite(s, line, sz); } -#else +# else /* We are after vfork here! */ /* move network socket to stdin/stdout */ xmove_fd(s, STDIN_FILENO); @@ -1542,7 +1545,7 @@ static void FAST_FUNC echo_stream(int s, servtab_t *sep UNUSED_PARAM) xopen(bb_dev_null, O_WRONLY); BB_EXECVP("cat", (char**)cat_args); /* on failure we return to main, which does exit(EXIT_FAILURE) */ -#endif +# endif } static void FAST_FUNC echo_dg(int s, servtab_t *sep) { @@ -1566,10 +1569,10 @@ static void FAST_FUNC echo_dg(int s, servtab_t *sep) /* ARGSUSED */ static void FAST_FUNC discard_stream(int s, servtab_t *sep UNUSED_PARAM) { -#if BB_MMU +# if BB_MMU while (safe_read(s, line, LINE_SIZE) > 0) continue; -#else +# else /* We are after vfork here! */ /* move network socket to stdin */ xmove_fd(s, STDIN_FILENO); @@ -1580,7 +1583,7 @@ static void FAST_FUNC discard_stream(int s, servtab_t *sep UNUSED_PARAM) xdup2(STDOUT_FILENO, STDERR_FILENO); BB_EXECVP("cat", (char**)cat_args); /* on failure we return to main, which does exit(EXIT_FAILURE) */ -#endif +# endif } /* ARGSUSED */ static void FAST_FUNC discard_dg(int s, servtab_t *sep UNUSED_PARAM) diff --git a/scripts/randomtest.loop b/scripts/randomtest.loop index 710f5fd05..4d14b652f 100755 --- a/scripts/randomtest.loop +++ b/scripts/randomtest.loop @@ -1,7 +1,11 @@ #!/bin/sh +run_testsuite=false run_testsuite=true +run_single_test=false +run_single_test=true + test -d "$1" || { echo "'$1' is not a directory"; exit 1; } test -x "$1/scripts/randomtest" || { echo "No scripts/randomtest in '$1'"; exit 1; } @@ -40,6 +44,28 @@ while sleep 1; do fi tail -n10 -- "$dir/testsuite/runtest.log" fi + if $run_single_test; then + ( + cd -- "$dir" || exit 1 + echo "Running make_single_applets.sh in $dir..." + + if grep -q '# CONFIG_FEATURE_TFTP_GET is not set' .config \ + && grep -q '# CONFIG_FEATURE_TFTP_PUT is not set' .config \ + ; then + # If both off, tftp[d] is ifdefed out and test fails. + # Enable one: + sed 's/# CONFIG_FEATURE_TFTP_GET is not set/CONFIG_FEATURE_TFTP_GET=y/' -i .config + fi + + ./make_single_applets.sh + ) + if test $? != 0; then + echo "Failed make_single_applets.sh in $dir" + exit 1 # you may comment this out... + let fail++ + continue + fi + fi rm -rf -- "$dir" let cnt++ done diff --git a/shell/hush.c b/shell/hush.c index fc6db316e..30add72f0 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1478,8 +1478,6 @@ typedef struct save_arg_t { static void save_and_replace_G_args(save_arg_t *sv, char **argv) { - int n; - sv->sv_argv0 = argv[0]; sv->sv_g_argv = G.global_argv; sv->sv_g_argc = G.global_argc; @@ -1489,10 +1487,7 @@ static void save_and_replace_G_args(save_arg_t *sv, char **argv) G.global_argv = argv; IF_HUSH_SET(G.global_args_malloced = 0;) - n = 1; - while (*++argv) - n++; - G.global_argc = n; + G.global_argc = 1 + string_array_len(argv + 1); } static void restore_G_args(save_arg_t *sv, char **argv) @@ -6809,13 +6804,11 @@ static void exec_function(char ***to_free, char **argv) { # if BB_MMU - int n = 1; + int n; argv[0] = G.global_argv[0]; G.global_argv = argv; - while (*++argv) - n++; - G.global_argc = n; + G.global_argc = n = 1 + string_array_len(argv + 1); /* On MMU, funcp->body is always non-NULL */ n = run_list(funcp->body); fflush_all(); @@ -8811,12 +8804,8 @@ static int FAST_FUNC builtin_true(char **argv UNUSED_PARAM) #if ENABLE_HUSH_TEST || ENABLE_HUSH_ECHO || ENABLE_HUSH_PRINTF || ENABLE_HUSH_KILL static int run_applet_main(char **argv, int (*applet_main_func)(int argc, char **argv)) { - int argc = 0; - while (*argv) { - argc++; - argv++; - } - return applet_main_func(argc, argv - argc); + int argc = string_array_len(argv); + return applet_main_func(argc, argv); } #endif #if ENABLE_HUSH_TEST || BASH_TEST2 @@ -9363,10 +9352,7 @@ static int FAST_FUNC builtin_set(char **argv) /* This realloc's G.global_argv */ G.global_argv = pp = add_strings_to_strings(g_argv, argv, /*dup:*/ 1); - n = 1; - while (*++pp) - n++; - G.global_argc = n; + G.global_argc = 1 + string_array_len(pp + 1); return EXIT_SUCCESS; diff --git a/shell/shell_common.c b/shell/shell_common.c index 03b7d0b75..bf56f3d78 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -405,9 +405,7 @@ shell_builtin_ulimit(char **argv) */ GETOPT_RESET(); - argc = 1; - while (argv[argc]) - argc++; + argc = string_array_len(argv); opts = 0; while (1) { diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 916d4e30e..4467525c7 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c @@ -185,6 +185,8 @@ struct hd_geometry { #define HDIO_GETGEO 0x0301 /* get device geometry */ +/* TODO: #if ENABLE_FEATURE_FDISK_WRITABLE */ +/* (currently fdisk_sun/sgi.c do not have proper WRITABLE #ifs) */ static const char msg_building_new_label[] ALIGN1 = "Building a new %s. Changes will remain in memory only,\n" "until you decide to write them. After that the previous content\n" @@ -192,6 +194,7 @@ static const char msg_building_new_label[] ALIGN1 = static const char msg_part_already_defined[] ALIGN1 = "Partition %u is already defined, delete it before re-adding\n"; +/* #endif */ struct partition { -- cgit v1.2.3-55-g6feb From 367a55c7d7e31a8162e795edc343277f8eb35f38 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 15 Jul 2017 14:52:26 +0200 Subject: build system: FEATURE_LIBBUSYBOX_STATIC - try to pull libc/libm into libbusybox It variously fails with different toolchains I tried... Signed-off-by: Denys Vlasenko --- Config.in | 43 ++++++++++++++++++++----------------------- scripts/trylink | 18 ++++++++++++------ 2 files changed, 32 insertions(+), 29 deletions(-) (limited to 'scripts') diff --git a/Config.in b/Config.in index cfb3aa0ee..82baed50a 100644 --- a/Config.in +++ b/Config.in @@ -386,29 +386,26 @@ config BUILD_LIBBUSYBOX Build a shared library libbusybox.so.N.N.N which contains all busybox code. - This feature allows every applet to be built as a tiny - separate executable. Enabling it for "one big busybox binary" - approach serves no purpose and increases code size. - You should almost certainly say "no" to this. - -### config FEATURE_FULL_LIBBUSYBOX -### bool "Feature-complete libbusybox" -### default n if !FEATURE_SHARED_BUSYBOX -### depends on BUILD_LIBBUSYBOX -### help -### Build a libbusybox with the complete feature-set, disregarding -### the actually selected config. -### -### Normally, libbusybox will only contain the features which are -### used by busybox itself. If you plan to write a separate -### standalone application which uses libbusybox say 'Y'. -### -### Note: libbusybox is GPL, not LGPL, and exports no stable API that -### might act as a copyright barrier. We can and will modify the -### exported function set between releases (even minor version number -### changes), and happily break out-of-tree features. -### -### Say 'N' if in doubt. + This feature allows every applet to be built as a really tiny + separate executable linked against the library: + + $ size 0_lib/l* + text data bss dec hex filename + 939 212 28 1179 49b 0_lib/last + 939 212 28 1179 49b 0_lib/less + 919138 8328 1556 929022 e2cfe 0_lib/libbusybox.so.1.N.M + + This is useful on NOMMU systems which are not capable + of sharing executables, but are capable of sharing code + in dynamic libraries. + +config FEATURE_LIBBUSYBOX_STATIC + bool "Pull in all external references into libbusybox" + default n + depends on BUILD_LIBBUSYBOX + help + Make libbusybox library independent, not using or requiring + any other shared libraries. config FEATURE_INDIVIDUAL bool "Produce a binary for each applet, linked against libbusybox" diff --git a/scripts/trylink b/scripts/trylink index 9f288c141..ba2d265bc 100755 --- a/scripts/trylink +++ b/scripts/trylink @@ -91,7 +91,9 @@ fi START_GROUP="-Wl,--start-group" END_GROUP="-Wl,--end-group" -INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" +INFO_OPTS() { + echo "-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" +} # gold may not support --sort-common (yet) SORT_COMMON="-Wl,--sort-common" @@ -194,7 +196,7 @@ if ! test -f busybox_ldscript; then $GC_SECTIONS \ $START_GROUP $O_FILES $A_FILES $END_GROUP \ $l_list \ - $INFO_OPTS \ + `INFO_OPTS` \ || { cat $EXE.out exit 1 @@ -225,7 +227,7 @@ else -Wl,-T,busybox_ldscript \ $START_GROUP $O_FILES $A_FILES $END_GROUP \ $l_list \ - $INFO_OPTS \ + `INFO_OPTS` \ || { cat $EXE.out exit 1 @@ -244,10 +246,14 @@ if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then } ln -s "libbusybox.so.$BB_VER" "$sharedlib_dir"/libbusybox.so 2>/dev/null + # Yes, "ld -shared -static" is a thing. It's a shared library which is itself static. + LBB_STATIC="" + test "$CONFIG_FEATURE_LIBBUSYBOX_STATIC" = y && LBB_STATIC="-Wl,-static" + EXE="$sharedlib_dir/libbusybox.so.${BB_VER}_unstripped" try $CC $CFLAGS $LDFLAGS \ -o $EXE \ - -shared -fPIC \ + -shared -fPIC $LBB_STATIC \ -Wl,--enable-new-dtags \ -Wl,-z,combreloc \ -Wl,-soname="libbusybox.so.$BB_VER" \ @@ -256,7 +262,7 @@ if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then $SORT_SECTION \ $START_GROUP $A_FILES $END_GROUP \ $l_list \ - $INFO_OPTS \ + `INFO_OPTS` \ || { echo "Linking $EXE failed" cat $EXE.out @@ -277,7 +283,7 @@ if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then $START_GROUP $O_FILES $END_GROUP \ -L"$sharedlib_dir" -lbusybox \ $l_list \ - $INFO_OPTS \ + `INFO_OPTS` \ || { echo "Linking $EXE failed" cat $EXE.out -- cgit v1.2.3-55-g6feb