From ebeac1685a6230abcf73ca36755e3bb208bfd569 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 18 Jun 2010 22:36:10 -0700 Subject: Define GNU-specific link options in one place This makes them easier to change to support a non-GNU toolchain. Signed-off-by: Dan Fandrich Signed-off-by: Denys Vlasenko --- scripts/trylink | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'scripts') diff --git a/scripts/trylink b/scripts/trylink index 164f5274c..021374aa9 100755 --- a/scripts/trylink +++ b/scripts/trylink @@ -85,6 +85,11 @@ LDLIBS="$7" # The --sort-section option is not supported by older versions of ld SORT_SECTION=`check_cc "-Wl,--sort-section,alignment" ""` +START_GROUP="-Wl,--start-group" +END_GROUP="-Wl,--end-group" + +INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" + # gold may not support --sort-common (yet) SORT_COMMON=`check_cc "-Wl,--sort-common" ""` @@ -114,13 +119,13 @@ LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs` echo "Trying libraries: $LDLIBS" # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` -test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" +test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" try $CC $CFLAGS $LDFLAGS \ -o $EXE \ $SORT_COMMON \ $SORT_SECTION \ $GC_SECTIONS \ - -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ + $START_GROUP $O_FILES $A_FILES $END_GROUP \ $l_list \ || { echo "Failed: $l_list" @@ -138,14 +143,14 @@ while test "$LDLIBS"; do without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` - test x"$l_list" != x"" && l_list="-Wl,--start-group $l_list -Wl,--end-group" + test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP" $debug && echo "Trying -l options: '$l_list'" try $CC $CFLAGS $LDFLAGS \ -o $EXE \ $SORT_COMMON \ $SORT_SECTION \ $GC_SECTIONS \ - -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ + $START_GROUP $O_FILES $A_FILES $END_GROUP \ $l_list if test $? = 0; then echo " Library $one is not needed, excluding it" @@ -169,7 +174,7 @@ done # Make the binary with final, minimal list of libs echo "Final link with: ${LDLIBS:-}" l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` -test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" +test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" # --verbose gives us gobs of info to stdout (e.g. linker script used) if ! test -f busybox_ldscript; then try $CC $CFLAGS $LDFLAGS \ @@ -177,11 +182,9 @@ if ! test -f busybox_ldscript; then $SORT_COMMON \ $SORT_SECTION \ $GC_SECTIONS \ - -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ + $START_GROUP $O_FILES $A_FILES $END_GROUP \ $l_list \ - -Wl,--warn-common \ - -Wl,-Map,$EXE.map \ - -Wl,--verbose \ + $INFO_OPTS \ || { cat $EXE.out exit 1 @@ -200,11 +203,9 @@ else $SORT_SECTION \ $GC_SECTIONS \ -Wl,-T,busybox_ldscript \ - -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ + $START_GROUP $O_FILES $A_FILES $END_GROUP \ $l_list \ - -Wl,--warn-common \ - -Wl,-Map,$EXE.map \ - -Wl,--verbose \ + $INFO_OPTS \ || { cat $EXE.out exit 1 @@ -233,11 +234,9 @@ if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then -Wl,--undefined=lbb_main \ $SORT_COMMON \ $SORT_SECTION \ - -Wl,--start-group $A_FILES -Wl,--end-group \ + $START_GROUP $A_FILES $END_GROUP \ $l_list \ - -Wl,--warn-common \ - -Wl,-Map,$EXE.map \ - -Wl,--verbose \ + $INFO_OPTS \ || { echo "Linking $EXE failed" cat $EXE.out @@ -255,11 +254,9 @@ if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then $SORT_COMMON \ $SORT_SECTION \ $GC_SECTIONS \ - -Wl,--start-group $O_FILES -Wl,--end-group \ + $START_GROUP $O_FILES $END_GROUP \ -L"$sharedlib_dir" -lbusybox \ - -Wl,--warn-common \ - -Wl,-Map,$EXE.map \ - -Wl,--verbose \ + $INFO_OPTS \ || { echo "Linking $EXE failed" cat $EXE.out -- cgit v1.2.3-55-g6feb From 134d0eb114ac67693eb62bb030dd537eca71c48d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 19 Jun 2010 20:07:23 +0200 Subject: cosmetics on top of Dan's patches Signed-off-by: Denys Vlasenko --- archival/libunarchive/unxz/xz_config.h | 4 ++-- networking/ipcalc.c | 4 +--- scripts/trylink | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/archival/libunarchive/unxz/xz_config.h b/archival/libunarchive/unxz/xz_config.h index a4141e136..187e1cbed 100644 --- a/archival/libunarchive/unxz/xz_config.h +++ b/archival/libunarchive/unxz/xz_config.h @@ -32,9 +32,9 @@ #define memeq(a, b, size) (memcmp(a, b, size) == 0) #define memzero(buf, size) memset(buf, 0, size) -#ifndef min +#undef min +#undef min_t #define min(x, y) ((x) < (y) ? (x) : (y)) -#endif #define min_t(type, x, y) min(x, y) /* diff --git a/networking/ipcalc.c b/networking/ipcalc.c index 87f31fdb5..265009ad8 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c @@ -11,10 +11,8 @@ * * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ - #include "libbb.h" - -#include +/* After libbb.h, because on some systems it needs other includes */ #include #define CLASS_A_NETMASK ntohl(0xFF000000) diff --git a/scripts/trylink b/scripts/trylink index 021374aa9..5994a757b 100755 --- a/scripts/trylink +++ b/scripts/trylink @@ -87,7 +87,6 @@ SORT_SECTION=`check_cc "-Wl,--sort-section,alignment" ""` START_GROUP="-Wl,--start-group" END_GROUP="-Wl,--end-group" - INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" # gold may not support --sort-common (yet) -- cgit v1.2.3-55-g6feb From 1d72d439405fdf4b51eb9e22c5c7a469695ae29c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 25 Jun 2010 13:30:59 +0200 Subject: gen_build_files.sh is an order prerequisite only for autoconf.h Signed-off-by: Denys Vlasenko --- Makefile | 2 +- scripts/gen_build_files.sh | 48 +++++++++++++++++++--------------------------- 2 files changed, 21 insertions(+), 29 deletions(-) (limited to 'scripts') diff --git a/Makefile b/Makefile index 87779d791..590512191 100644 --- a/Makefile +++ b/Makefile @@ -509,7 +509,7 @@ include $(srctree)/Makefile.flags # with it and forgot to run make oldconfig. # If kconfig.d is missing then we are probarly in a cleaned tree so # we execute the config step to be sure to catch updated Kconfig files -include/autoconf.h: .kconfig.d .config gen_build_files +include/autoconf.h: .kconfig.d .config | gen_build_files $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig else diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh index 647c7daf7..a98f509ce 100755 --- a/scripts/gen_build_files.sh +++ b/scripts/gen_build_files.sh @@ -11,20 +11,19 @@ srctree="$1" src="$srctree/include/applets.src.h" dst="include/applets.h" s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c` -echo "/* DO NOT EDIT. This file is generated from applets.src.h */" >"$dst.$$.tmp" +old=`cat "$dst" 2>/dev/null` # Why "IFS='' read -r REPLY"?? # This atrocity is needed to read lines without mangling. # IFS='' prevents whitespace trimming, # -r suppresses backslash handling. +new=`echo "/* DO NOT EDIT. This file is generated from applets.src.h */" while IFS='' read -r REPLY; do test x"$REPLY" = x"INSERT" && REPLY="$s" printf "%s\n" "$REPLY" -done <"$src" >>"$dst.$$.tmp" -if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then - rm -- "$dst.$$.tmp" -else +done <"$src"` +if test x"$new" != x"$old"; then echo " GEN $dst" - mv -- "$dst.$$.tmp" "$dst" + printf "%s\n" "$new" >"$dst" fi # (Re)generate include/usage.h @@ -35,20 +34,15 @@ dst="include/usage.h" # with space or tab # (note: we need to use \\\\ because of ``) s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c` -echo "/* DO NOT EDIT. This file is generated from usage.src.h */" >"$dst.$$.tmp" -# Why "IFS='' read -r REPLY"?? -# This atrocity is needed to read lines without mangling. -# IFS='' prevents whitespace trimming, -# -r suppresses backslash handling. +old=`cat "$dst" 2>/dev/null` +new=`echo "/* DO NOT EDIT. This file is generated from usage.src.h */" while IFS='' read -r REPLY; do test x"$REPLY" = x"INSERT" && REPLY="$s" printf "%s\n" "$REPLY" -done <"$src" >>"$dst.$$.tmp" -if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then - rm -- "$dst.$$.tmp" -else +done <"$src"` +if test x"$new" != x"$old"; then echo " GEN $dst" - mv -- "$dst.$$.tmp" "$dst" + printf "%s\n" "$new" >"$dst" fi # (Re)generate */Kbuild and */Config.in @@ -61,16 +55,15 @@ find -type d | while read -r d; do s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` - echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp" + old=`cat "$dst" 2>/dev/null` + new=`echo "# DO NOT EDIT. This file is generated from Kbuild.src" while IFS='' read -r REPLY; do test x"$REPLY" = x"INSERT" && REPLY="$s" printf "%s\n" "$REPLY" - done <"$src" >>"$dst.$$.tmp" - if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then - rm -- "$dst.$$.tmp" - else + done <"$src"` + if test x"$new" != x"$old"; then echo " GEN $dst" - mv -- "$dst.$$.tmp" "$dst" + printf "%s\n" "$new" >"$dst" fi fi @@ -81,16 +74,15 @@ find -type d | while read -r d; do s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` - echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp" + old=`cat "$dst" 2>/dev/null` + new=`echo "# DO NOT EDIT. This file is generated from Config.src" while IFS='' read -r REPLY; do test x"$REPLY" = x"INSERT" && REPLY="$s" printf "%s\n" "$REPLY" - done <"$src" >>"$dst.$$.tmp" - if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then - rm -- "$dst.$$.tmp" - else + done <"$src"` + if test x"$new" != x"$old"; then echo " GEN $dst" - mv -- "$dst.$$.tmp" "$dst" + printf "%s\n" "$new" >"$dst" fi fi done -- cgit v1.2.3-55-g6feb From 926031b7640bf5aad2ffcd54b096911743a47d97 Mon Sep 17 00:00:00 2001 From: Pascal Bellard Date: Sun, 4 Jul 2010 15:32:38 +0200 Subject: *: introduce and use xfork() and xvfork() function old new delta launch_helper 170 169 -1 setup_heredoc 312 302 -10 handle_dir_common 367 354 -13 expand_vars_to_list 2456 2443 -13 open_transformer 89 74 -15 data_extract_to_command 439 423 -16 do_ipaddr 1406 1389 -17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-85) Total: -85 bytes Signed-off-by: Pascal Bellard Signed-off-by: Denys Vlasenko --- archival/libunarchive/data_extract_to_command.c | 7 ++----- archival/libunarchive/open_transformer.c | 14 ++------------ archival/tar.c | 4 +--- debianutils/start_stop_daemon.c | 4 +--- e2fsprogs/old_e2fsprogs/fsck.c | 2 +- include/libbb.h | 21 +++++++++++++++++---- init/bootchartd.c | 4 +--- libbb/vfork_daemon_rexec.c | 16 +--------------- libbb/xfuncs_printf.c | 11 +++++++++++ mailutils/mail.c | 4 +--- miscutils/conspy.c | 5 +---- miscutils/crontab.c | 8 ++------ miscutils/time.c | 4 +--- miscutils/timeout.c | 4 +--- networking/ftpd.c | 5 +---- networking/ifupdown.c | 8 +++----- networking/inetd.c | 2 +- networking/nc.c | 6 ++---- scripts/basic/docproc.c | 2 +- shell/hush.c | 15 ++++----------- util-linux/script.c | 5 +---- 21 files changed, 56 insertions(+), 95 deletions(-) (limited to 'scripts') diff --git a/archival/libunarchive/data_extract_to_command.c b/archival/libunarchive/data_extract_to_command.c index eb09439bc..95f5bc864 100644 --- a/archival/libunarchive/data_extract_to_command.c +++ b/archival/libunarchive/data_extract_to_command.c @@ -82,11 +82,8 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle) memset(tar_env, 0, sizeof(tar_env)); xpipe(p); - pid = BB_MMU ? fork() : vfork(); - switch (pid) { - case -1: - bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); - case 0: + pid = BB_MMU ? xfork() : xvfork(); + if (pid == 0) { /* Child */ /* str2env(tar_env, TAR_FILETYPE, "f"); - parent should do it once */ oct2env(tar_env, TAR_MODE, file_header->mode); diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c index 47c13e6f4..cba049f1f 100644 --- a/archival/libunarchive/open_transformer.c +++ b/archival/libunarchive/open_transformer.c @@ -19,19 +19,9 @@ void FAST_FUNC open_transformer(int fd, int pid; xpiped_pair(fd_pipe); - -#if BB_MMU - pid = fork(); - if (pid == -1) - bb_perror_msg_and_die("vfork" + 1); -#else - pid = vfork(); - if (pid == -1) - bb_perror_msg_and_die("vfork"); -#endif - + pid = BB_MMU ? xfork() : xvfork(); if (pid == 0) { - /* child process */ + /* Child */ close(fd_pipe.rd); /* we don't want to read from the parent */ // FIXME: error check? #if BB_MMU diff --git a/archival/tar.c b/archival/tar.c index f49fb129e..9dd74536e 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -514,9 +514,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip) (void) &zip_exec; # endif - gzipPid = vfork(); - if (gzipPid < 0) - bb_perror_msg_and_die("vfork"); + gzipPid = xvfork(); if (gzipPid == 0) { /* child */ diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 3ded758bf..665f38fbd 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -409,9 +409,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) /* DAEMON_DEVNULL_STDIO is superfluous - * it's always done by bb_daemonize() */ #else - pid_t pid = vfork(); - if (pid < 0) /* error */ - bb_perror_msg_and_die("vfork"); + pid_t pid = xvfork(); if (pid != 0) { /* parent */ /* why _exit? the child may have changed the stack, diff --git a/e2fsprogs/old_e2fsprogs/fsck.c b/e2fsprogs/old_e2fsprogs/fsck.c index dc029b65a..2a66d728a 100644 --- a/e2fsprogs/old_e2fsprogs/fsck.c +++ b/e2fsprogs/old_e2fsprogs/fsck.c @@ -612,7 +612,7 @@ static int execute(const char *type, const char *device, const char *mntpt, if (noexecute) pid = -1; else if ((pid = fork()) < 0) { - perror("fork"); + perror("vfork"+1); return errno; } else if (pid == 0) { if (!interactive) diff --git a/include/libbb.h b/include/libbb.h index 4b6699f2f..e2a8322b8 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -841,6 +841,19 @@ int bb_execvp(const char *file, char *const argv[]) FAST_FUNC; #endif int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; +/* xvfork() can't be a _function_, return after vfork mangles stack + * in the parent. It must be a macro. */ +#define xvfork() \ +({ \ + pid_t bb__xvfork_pid = vfork(); \ + if (bb__xvfork_pid < 0) \ + bb_perror_msg_and_die("vfork"); \ + bb__xvfork_pid; \ +}) +#if BB_MMU +pid_t xfork(void) FAST_FUNC; +#endif + /* NOMMU friendy fork+exec: */ pid_t spawn(char **argv) FAST_FUNC; pid_t xspawn(char **argv) FAST_FUNC; @@ -886,7 +899,7 @@ int run_nofork_applet_prime(struct nofork_save_area *old, int applet_no, char ** * Both of the above will redirect fd 0,1,2 to /dev/null and drop ctty * (will do setsid()). * - * fork_or_rexec(argv) = bare-bones "fork" on MMU, + * fork_or_rexec(argv) = bare-bones fork on MMU, * "vfork + re-exec ourself" on NOMMU. No fd redirection, no setsid(). * On MMU ignores argv. * @@ -902,19 +915,19 @@ enum { DAEMON_ONLY_SANITIZE = 8, /* internal use */ }; #if BB_MMU - pid_t fork_or_rexec(void) FAST_FUNC; enum { re_execed = 0 }; -# define fork_or_rexec(argv) fork_or_rexec() +# define fork_or_rexec(argv) xfork() # define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags) # define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus) #else + extern bool re_execed; void re_exec(char **argv) NORETURN FAST_FUNC; pid_t fork_or_rexec(char **argv) FAST_FUNC; - extern bool re_execed; int BUG_fork_is_unavailable_on_nommu(void) FAST_FUNC; int BUG_daemon_is_unavailable_on_nommu(void) FAST_FUNC; void BUG_bb_daemonize_is_unavailable_on_nommu(void) FAST_FUNC; # define fork() BUG_fork_is_unavailable_on_nommu() +# define xfork() BUG_fork_is_unavailable_on_nommu() # define daemon(a,b) BUG_daemon_is_unavailable_on_nommu() # define bb_daemonize(a) BUG_bb_daemonize_is_unavailable_on_nommu() #endif diff --git a/init/bootchartd.c b/init/bootchartd.c index 42b98c827..b3e08af92 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -427,9 +427,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) } if (cmd == CMD_START && argv[2]) { /* "start PROG ARGS" */ - pid_t pid = vfork(); - if (pid < 0) - bb_perror_msg_and_die("vfork"); + pid_t pid = xvfork(); if (pid == 0) { /* child */ argv += 2; execvp(argv[0], argv); diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 8102ea2dc..5c2c529c9 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c @@ -224,26 +224,12 @@ pid_t FAST_FUNC fork_or_rexec(char **argv) /* Maybe we are already re-execed and come here again? */ if (re_execed) return 0; - pid = vfork(); - if (pid < 0) /* wtf? */ - bb_perror_msg_and_die("vfork"); + pid = xvfork(); if (pid) /* parent */ return pid; /* child - re-exec ourself */ re_exec(argv); } -#else -/* Dance around (void)...*/ -#undef fork_or_rexec -pid_t FAST_FUNC fork_or_rexec(void) -{ - pid_t pid; - pid = fork(); - if (pid < 0) /* wtf? */ - bb_perror_msg_and_die("fork"); - return pid; -} -#define fork_or_rexec(argv) fork_or_rexec() #endif /* Due to a #define in libbb.h on MMU systems we actually have 1 argument - diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index f021493b1..7069a7c8e 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -589,3 +589,14 @@ void FAST_FUNC generate_uuid(uint8_t *buf) /* variant = 10x */ buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; } + +#if BB_MMU +pid_t FAST_FUNC xfork(void) +{ + pid_t pid; + pid = fork(); + if (pid < 0) /* wtf? */ + bb_perror_msg_and_die("vfork"+1); + return pid; +} +#endif diff --git a/mailutils/mail.c b/mailutils/mail.c index 5eb99e13d..bcd358302 100644 --- a/mailutils/mail.c +++ b/mailutils/mail.c @@ -54,9 +54,7 @@ void FAST_FUNC launch_helper(const char **argv) + (1 << SIGALRM) , signal_handler); - G.helper_pid = vfork(); - if (G.helper_pid < 0) - bb_perror_msg_and_die("vfork"); + G.helper_pid = xvfork(); i = (!G.helper_pid) * 2; // for parent:0, for child:2 close(pipes[i + 1]); // 1 or 3 - closing one write end diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 3f341ce18..509a0f271 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c @@ -309,10 +309,7 @@ static void create_cdev_if_doesnt_exist(const char* name, dev_t dev) static NOINLINE void start_shell_in_child(const char* tty_name) { - int pid = vfork(); - if (pid < 0) { - bb_perror_msg_and_die("vfork"); - } + int pid = xvfork(); if (pid == 0) { struct termios termchild; char *shell = getenv("SHELL"); diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 5557bc491..b8a5abc64 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -20,10 +20,8 @@ static void edit_file(const struct passwd *pas, const char *file) { const char *ptr; - int pid = vfork(); + int pid = xvfork(); - if (pid < 0) /* failure */ - bb_perror_msg_and_die("vfork"); if (pid) { /* parent */ wait4pid(pid); return; @@ -51,9 +49,7 @@ static int open_as_user(const struct passwd *pas, const char *file) pid_t pid; char c; - pid = vfork(); - if (pid < 0) /* ERROR */ - bb_perror_msg_and_die("vfork"); + pid = xvfork(); if (pid) { /* PARENT */ if (wait4pid(pid) == 0) { /* exitcode 0: child says it can read */ diff --git a/miscutils/time.c b/miscutils/time.c index 5cfbcef8e..9facc3657 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -372,9 +372,7 @@ static void run_command(char *const *cmd, resource_t *resp) void (*quit_signal)(int); resp->elapsed_ms = monotonic_ms(); - pid = vfork(); - if (pid < 0) - bb_perror_msg_and_die("vfork"); + pid = xvfork(); if (pid == 0) { /* Child */ BB_EXECVP_or_die((char**)cmd); diff --git a/miscutils/timeout.c b/miscutils/timeout.c index f6e655acc..48b8d8fc0 100644 --- a/miscutils/timeout.c +++ b/miscutils/timeout.c @@ -71,9 +71,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) sv1 = argv[optind]; sv2 = argv[optind + 1]; #endif - pid = vfork(); - if (pid < 0) - bb_perror_msg_and_die("vfork"); + pid = xvfork(); if (pid == 0) { /* Child: spawn grandchild and exit */ parent = getppid(); diff --git a/networking/ftpd.c b/networking/ftpd.c index c63b9319e..e8cae0a36 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c @@ -632,10 +632,7 @@ popen_ls(const char *opt) xpiped_pair(outfd); /*fflush_all(); - so far we dont use stdio on output */ - pid = BB_MMU ? fork() : vfork(); - if (pid < 0) - bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); - + pid = BB_MMU ? xfork() : xvfork(); if (pid == 0) { /* child */ #if !BB_MMU diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 1bab2c5cb..69c56e879 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -1041,12 +1041,10 @@ static int popen2(FILE **in, FILE **out, char *command, char *param) xpiped_pair(outfd); fflush_all(); - pid = vfork(); + pid = xvfork(); - switch (pid) { - case -1: /* failure */ - bb_perror_msg_and_die("vfork"); - case 0: /* child */ + if (pid == 0) { + /* Child */ /* NB: close _first_, then move fds! */ close(infd.wr); close(outfd.rd); diff --git a/networking/inetd.c b/networking/inetd.c index 2b0e0069e..7030062b6 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -1271,7 +1271,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) pid = vfork(); if (pid < 0) { /* fork error */ - bb_perror_msg("fork"); + bb_perror_msg("vfork"+1); sleep(1); restore_sigmask(&omask); maybe_close(accepted_fd); diff --git a/networking/nc.c b/networking/nc.c index 5fd8bd759..0dacaf117 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -216,10 +216,8 @@ int nc_main(int argc, char **argv) if (execparam) { pid_t pid; /* With more than one -l, repeatedly act as server */ - if (do_listen > 1 && (pid = vfork()) != 0) { - /* parent or error */ - if (pid < 0) - bb_perror_msg_and_die("vfork"); + if (do_listen > 1 && (pid = xvfork()) != 0) { + /* parent */ /* prevent zombies */ signal(SIGCHLD, SIG_IGN); close(cfd); diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c index ef5181226..50ef37157 100644 --- a/scripts/basic/docproc.c +++ b/scripts/basic/docproc.c @@ -86,7 +86,7 @@ void exec_kernel_doc(char **svec) fflush(stdout); switch(pid=fork()) { case -1: - perror("fork"); + perror("vfork"+1); exit(1); case 0: rflen = strlen(getenv("SRCTREE")); diff --git a/shell/hush.c b/shell/hush.c index 29ff3c442..831443e2e 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -3208,15 +3208,11 @@ static void setup_heredoc(struct redir_struct *redir) #if !BB_MMU to_free = NULL; #endif - pid = vfork(); - if (pid < 0) - bb_perror_msg_and_die("vfork"); + pid = xvfork(); if (pid == 0) { /* child */ disable_restore_tty_pgrp_on_exit(); - pid = BB_MMU ? fork() : vfork(); - if (pid < 0) - bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); + pid = BB_MMU ? xfork() : xvfork(); if (pid != 0) _exit(0); /* grandchild */ @@ -4450,7 +4446,7 @@ static NOINLINE int run_pipe(struct pipe *pi) argv_expanded = NULL; if (command->pid < 0) { /* [v]fork failed */ /* Clearly indicate, was it fork or vfork */ - bb_perror_msg(BB_MMU ? "fork" : "vfork"); + bb_perror_msg(BB_MMU ? "vfork"+1 : "vfork"); } else { pi->alive_cmds++; #if ENABLE_HUSH_JOB @@ -5586,10 +5582,7 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p) # endif xpipe(channel); - pid = BB_MMU ? fork() : vfork(); - if (pid < 0) - bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); - + pid = BB_MMU ? xfork() : xvfork(); if (pid == 0) { /* child */ disable_restore_tty_pgrp_on_exit(); /* Process substitution is not considered to be usual diff --git a/util-linux/script.c b/util-linux/script.c index d9a62fbfe..c23117cf3 100644 --- a/util-linux/script.c +++ b/util-linux/script.c @@ -88,10 +88,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) /* TODO: SIGWINCH? pass window size changes down to slave? */ - child_pid = vfork(); - if (child_pid < 0) { - bb_perror_msg_and_die("vfork"); - } + child_pid = xvfork(); if (child_pid) { /* parent */ -- cgit v1.2.3-55-g6feb From 3e5fa43b2faba827e44f184818534b476ec0ed09 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 6 Jul 2010 02:26:35 +0200 Subject: scripts/randomtest: update to pass testsuite with Rob's toolchain Signed-off-by: Denys Vlasenko --- scripts/randomtest | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/randomtest b/scripts/randomtest index 8d0d79e64..a102593d3 100755 --- a/scripts/randomtest +++ b/scripts/randomtest @@ -43,6 +43,10 @@ mv .config.new .config echo '# CONFIG_DEBUG_PESSIMIZE is not set' >>.config echo '# CONFIG_WERROR is not set' >>.config echo "CONFIG_CROSS_COMPILER_PREFIX=\"${CROSS_COMPILER_PREFIX}\"" >>.config +echo '# CONFIG_SELINUX is not set' >>.config +echo '# CONFIG_EFENCE is not set' >>.config +echo '# CONFIG_DMALLOC is not set' >>.config +echo '# CONFIG_RFKILL is not set' >>.config # If glibc, don't build static if test x"$LIBC" = x"glibc"; then @@ -53,18 +57,21 @@ if test x"$LIBC" = x"glibc"; then echo '# CONFIG_STATIC is not set' >>.config fi -# If glibc, build static, and remove some things +# If uclibc, build static, and remove some things # likely to not work on uclibc. if test x"$LIBC" = x"uclibc"; then cat .config \ | grep -v CONFIG_STATIC \ | grep -v CONFIG_BUILD_LIBBUSYBOX \ - | grep -v CONFIG_TASKSET \ - | grep -v CONFIG_UNICODE_SUPPORT \ | grep -v CONFIG_PIE \ + \ + | grep -v CONFIG_FEATURE_2_4_MODULES \ >.config.new mv .config.new .config echo 'CONFIG_STATIC=y' >>.config + echo '# CONFIG_BUILD_LIBBUSYBOX is not set' >>.config + echo '# CONFIG_PIE is not set' >>.config + echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config fi # If STATIC, remove some things. @@ -75,6 +82,7 @@ if grep -q "^CONFIG_STATIC=y" .config; then | grep -v CONFIG_PAM \ >.config.new mv .config.new .config + echo '# CONFIG_PAM is not set' >>.config fi # Regenerate .config with default answers for yanked-off options -- cgit v1.2.3-55-g6feb From 1883cb174619cfc90ca86da08598f470d3a11315 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 9 Jul 2010 01:25:36 +0200 Subject: fix make O=dir build Signed-off-by: Denys Vlasenko --- scripts/Makefile.build | 7 ++++++- scripts/gen_build_files.sh | 7 ++++++- scripts/test_make_O | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100755 scripts/test_make_O (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index f343818b1..5685b5bcc 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -13,8 +13,13 @@ __build: include scripts/Kbuild.include # The filename Kbuild has precedence over Makefile +# bbox: we also try to include Kbuild file in obj tree first kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) -include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile) +include $(if $(wildcard $(src)/Kbuild), $(src)/Kbuild, \ + $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, \ + $(kbuild-dir)/Makefile \ + ) \ + ) include scripts/Makefile.lib diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh index a98f509ce..968158758 100755 --- a/scripts/gen_build_files.sh +++ b/scripts/gen_build_files.sh @@ -4,6 +4,8 @@ test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } # cd to objtree cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } +# In separate objtree build, include/ might not exist yet +mkdir include 2>/dev/null srctree="$1" @@ -46,10 +48,12 @@ if test x"$new" != x"$old"; then fi # (Re)generate */Kbuild and */Config.in -find -type d | while read -r d; do +{ cd -- "$srctree" && find -type d; } | while read -r d; do d="${d#./}" + src="$srctree/$d/Kbuild.src" dst="$d/Kbuild" + mkdir -p -- "$d" 2>/dev/null if test -f "$src"; then #echo " CHK $dst" @@ -69,6 +73,7 @@ find -type d | while read -r d; do src="$srctree/$d/Config.src" dst="$d/Config.in" + mkdir -p -- "$d" 2>/dev/null if test -f "$src"; then #echo " CHK $dst" diff --git a/scripts/test_make_O b/scripts/test_make_O new file mode 100755 index 000000000..a0ee6a868 --- /dev/null +++ b/scripts/test_make_O @@ -0,0 +1,11 @@ +#!/bin/sh + +b=`basename $PWD` +test "${b#busybox}" != "$b" || { echo "Must be run in busybox tree"; exit 1; } + +rm -rf ../testdir_make_O.$$ +mkdir ../testdir_make_O.$$ +odir=`cd ../testdir_make_O.$$ && pwd` +test -d "$odir" || exit 1 + +make O="$odir" $MAKEOPTS "$@" defconfig busybox 2>&1 | tee test_make_O.log -- cgit v1.2.3-55-g6feb