diff options
author | Pascal Bellard <pascal.bellard@ads-lu.com> | 2010-07-04 15:32:38 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-07-04 15:32:38 +0200 |
commit | 926031b7640bf5aad2ffcd54b096911743a47d97 (patch) | |
tree | 093e0e1bab2c905a97c5880e4942e2000ada7e72 | |
parent | 243d1757d798a0cd43f51eb1db75cc1e81c65732 (diff) | |
download | busybox-w32-926031b7640bf5aad2ffcd54b096911743a47d97.tar.gz busybox-w32-926031b7640bf5aad2ffcd54b096911743a47d97.tar.bz2 busybox-w32-926031b7640bf5aad2ffcd54b096911743a47d97.zip |
*: 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 <pascal.bellard@ads-lu.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/libunarchive/data_extract_to_command.c | 7 | ||||
-rw-r--r-- | archival/libunarchive/open_transformer.c | 14 | ||||
-rw-r--r-- | archival/tar.c | 4 | ||||
-rw-r--r-- | debianutils/start_stop_daemon.c | 4 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/fsck.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 21 | ||||
-rw-r--r-- | init/bootchartd.c | 4 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 16 | ||||
-rw-r--r-- | libbb/xfuncs_printf.c | 11 | ||||
-rw-r--r-- | mailutils/mail.c | 4 | ||||
-rw-r--r-- | miscutils/conspy.c | 5 | ||||
-rw-r--r-- | miscutils/crontab.c | 8 | ||||
-rw-r--r-- | miscutils/time.c | 4 | ||||
-rw-r--r-- | miscutils/timeout.c | 4 | ||||
-rw-r--r-- | networking/ftpd.c | 5 | ||||
-rw-r--r-- | networking/ifupdown.c | 8 | ||||
-rw-r--r-- | networking/inetd.c | 2 | ||||
-rw-r--r-- | networking/nc.c | 6 | ||||
-rw-r--r-- | scripts/basic/docproc.c | 2 | ||||
-rw-r--r-- | shell/hush.c | 15 | ||||
-rw-r--r-- | util-linux/script.c | 5 |
21 files changed, 56 insertions, 95 deletions
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) | |||
82 | memset(tar_env, 0, sizeof(tar_env)); | 82 | memset(tar_env, 0, sizeof(tar_env)); |
83 | 83 | ||
84 | xpipe(p); | 84 | xpipe(p); |
85 | pid = BB_MMU ? fork() : vfork(); | 85 | pid = BB_MMU ? xfork() : xvfork(); |
86 | switch (pid) { | 86 | if (pid == 0) { |
87 | case -1: | ||
88 | bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); | ||
89 | case 0: | ||
90 | /* Child */ | 87 | /* Child */ |
91 | /* str2env(tar_env, TAR_FILETYPE, "f"); - parent should do it once */ | 88 | /* str2env(tar_env, TAR_FILETYPE, "f"); - parent should do it once */ |
92 | oct2env(tar_env, TAR_MODE, file_header->mode); | 89 | 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, | |||
19 | int pid; | 19 | int pid; |
20 | 20 | ||
21 | xpiped_pair(fd_pipe); | 21 | xpiped_pair(fd_pipe); |
22 | 22 | pid = BB_MMU ? xfork() : xvfork(); | |
23 | #if BB_MMU | ||
24 | pid = fork(); | ||
25 | if (pid == -1) | ||
26 | bb_perror_msg_and_die("vfork" + 1); | ||
27 | #else | ||
28 | pid = vfork(); | ||
29 | if (pid == -1) | ||
30 | bb_perror_msg_and_die("vfork"); | ||
31 | #endif | ||
32 | |||
33 | if (pid == 0) { | 23 | if (pid == 0) { |
34 | /* child process */ | 24 | /* Child */ |
35 | close(fd_pipe.rd); /* we don't want to read from the parent */ | 25 | close(fd_pipe.rd); /* we don't want to read from the parent */ |
36 | // FIXME: error check? | 26 | // FIXME: error check? |
37 | #if BB_MMU | 27 | #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) | |||
514 | (void) &zip_exec; | 514 | (void) &zip_exec; |
515 | # endif | 515 | # endif |
516 | 516 | ||
517 | gzipPid = vfork(); | 517 | gzipPid = xvfork(); |
518 | if (gzipPid < 0) | ||
519 | bb_perror_msg_and_die("vfork"); | ||
520 | 518 | ||
521 | if (gzipPid == 0) { | 519 | if (gzipPid == 0) { |
522 | /* child */ | 520 | /* 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) | |||
409 | /* DAEMON_DEVNULL_STDIO is superfluous - | 409 | /* DAEMON_DEVNULL_STDIO is superfluous - |
410 | * it's always done by bb_daemonize() */ | 410 | * it's always done by bb_daemonize() */ |
411 | #else | 411 | #else |
412 | pid_t pid = vfork(); | 412 | pid_t pid = xvfork(); |
413 | if (pid < 0) /* error */ | ||
414 | bb_perror_msg_and_die("vfork"); | ||
415 | if (pid != 0) { | 413 | if (pid != 0) { |
416 | /* parent */ | 414 | /* parent */ |
417 | /* why _exit? the child may have changed the stack, | 415 | /* 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, | |||
612 | if (noexecute) | 612 | if (noexecute) |
613 | pid = -1; | 613 | pid = -1; |
614 | else if ((pid = fork()) < 0) { | 614 | else if ((pid = fork()) < 0) { |
615 | perror("fork"); | 615 | perror("vfork"+1); |
616 | return errno; | 616 | return errno; |
617 | } else if (pid == 0) { | 617 | } else if (pid == 0) { |
618 | if (!interactive) | 618 | 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; | |||
841 | #endif | 841 | #endif |
842 | int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; | 842 | int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; |
843 | 843 | ||
844 | /* xvfork() can't be a _function_, return after vfork mangles stack | ||
845 | * in the parent. It must be a macro. */ | ||
846 | #define xvfork() \ | ||
847 | ({ \ | ||
848 | pid_t bb__xvfork_pid = vfork(); \ | ||
849 | if (bb__xvfork_pid < 0) \ | ||
850 | bb_perror_msg_and_die("vfork"); \ | ||
851 | bb__xvfork_pid; \ | ||
852 | }) | ||
853 | #if BB_MMU | ||
854 | pid_t xfork(void) FAST_FUNC; | ||
855 | #endif | ||
856 | |||
844 | /* NOMMU friendy fork+exec: */ | 857 | /* NOMMU friendy fork+exec: */ |
845 | pid_t spawn(char **argv) FAST_FUNC; | 858 | pid_t spawn(char **argv) FAST_FUNC; |
846 | pid_t xspawn(char **argv) FAST_FUNC; | 859 | 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 ** | |||
886 | * Both of the above will redirect fd 0,1,2 to /dev/null and drop ctty | 899 | * Both of the above will redirect fd 0,1,2 to /dev/null and drop ctty |
887 | * (will do setsid()). | 900 | * (will do setsid()). |
888 | * | 901 | * |
889 | * fork_or_rexec(argv) = bare-bones "fork" on MMU, | 902 | * fork_or_rexec(argv) = bare-bones fork on MMU, |
890 | * "vfork + re-exec ourself" on NOMMU. No fd redirection, no setsid(). | 903 | * "vfork + re-exec ourself" on NOMMU. No fd redirection, no setsid(). |
891 | * On MMU ignores argv. | 904 | * On MMU ignores argv. |
892 | * | 905 | * |
@@ -902,19 +915,19 @@ enum { | |||
902 | DAEMON_ONLY_SANITIZE = 8, /* internal use */ | 915 | DAEMON_ONLY_SANITIZE = 8, /* internal use */ |
903 | }; | 916 | }; |
904 | #if BB_MMU | 917 | #if BB_MMU |
905 | pid_t fork_or_rexec(void) FAST_FUNC; | ||
906 | enum { re_execed = 0 }; | 918 | enum { re_execed = 0 }; |
907 | # define fork_or_rexec(argv) fork_or_rexec() | 919 | # define fork_or_rexec(argv) xfork() |
908 | # define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags) | 920 | # define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags) |
909 | # define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus) | 921 | # define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus) |
910 | #else | 922 | #else |
923 | extern bool re_execed; | ||
911 | void re_exec(char **argv) NORETURN FAST_FUNC; | 924 | void re_exec(char **argv) NORETURN FAST_FUNC; |
912 | pid_t fork_or_rexec(char **argv) FAST_FUNC; | 925 | pid_t fork_or_rexec(char **argv) FAST_FUNC; |
913 | extern bool re_execed; | ||
914 | int BUG_fork_is_unavailable_on_nommu(void) FAST_FUNC; | 926 | int BUG_fork_is_unavailable_on_nommu(void) FAST_FUNC; |
915 | int BUG_daemon_is_unavailable_on_nommu(void) FAST_FUNC; | 927 | int BUG_daemon_is_unavailable_on_nommu(void) FAST_FUNC; |
916 | void BUG_bb_daemonize_is_unavailable_on_nommu(void) FAST_FUNC; | 928 | void BUG_bb_daemonize_is_unavailable_on_nommu(void) FAST_FUNC; |
917 | # define fork() BUG_fork_is_unavailable_on_nommu() | 929 | # define fork() BUG_fork_is_unavailable_on_nommu() |
930 | # define xfork() BUG_fork_is_unavailable_on_nommu() | ||
918 | # define daemon(a,b) BUG_daemon_is_unavailable_on_nommu() | 931 | # define daemon(a,b) BUG_daemon_is_unavailable_on_nommu() |
919 | # define bb_daemonize(a) BUG_bb_daemonize_is_unavailable_on_nommu() | 932 | # define bb_daemonize(a) BUG_bb_daemonize_is_unavailable_on_nommu() |
920 | #endif | 933 | #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) | |||
427 | } | 427 | } |
428 | 428 | ||
429 | if (cmd == CMD_START && argv[2]) { /* "start PROG ARGS" */ | 429 | if (cmd == CMD_START && argv[2]) { /* "start PROG ARGS" */ |
430 | pid_t pid = vfork(); | 430 | pid_t pid = xvfork(); |
431 | if (pid < 0) | ||
432 | bb_perror_msg_and_die("vfork"); | ||
433 | if (pid == 0) { /* child */ | 431 | if (pid == 0) { /* child */ |
434 | argv += 2; | 432 | argv += 2; |
435 | execvp(argv[0], argv); | 433 | 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) | |||
224 | /* Maybe we are already re-execed and come here again? */ | 224 | /* Maybe we are already re-execed and come here again? */ |
225 | if (re_execed) | 225 | if (re_execed) |
226 | return 0; | 226 | return 0; |
227 | pid = vfork(); | 227 | pid = xvfork(); |
228 | if (pid < 0) /* wtf? */ | ||
229 | bb_perror_msg_and_die("vfork"); | ||
230 | if (pid) /* parent */ | 228 | if (pid) /* parent */ |
231 | return pid; | 229 | return pid; |
232 | /* child - re-exec ourself */ | 230 | /* child - re-exec ourself */ |
233 | re_exec(argv); | 231 | re_exec(argv); |
234 | } | 232 | } |
235 | #else | ||
236 | /* Dance around (void)...*/ | ||
237 | #undef fork_or_rexec | ||
238 | pid_t FAST_FUNC fork_or_rexec(void) | ||
239 | { | ||
240 | pid_t pid; | ||
241 | pid = fork(); | ||
242 | if (pid < 0) /* wtf? */ | ||
243 | bb_perror_msg_and_die("fork"); | ||
244 | return pid; | ||
245 | } | ||
246 | #define fork_or_rexec(argv) fork_or_rexec() | ||
247 | #endif | 233 | #endif |
248 | 234 | ||
249 | /* Due to a #define in libbb.h on MMU systems we actually have 1 argument - | 235 | /* 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) | |||
589 | /* variant = 10x */ | 589 | /* variant = 10x */ |
590 | buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; | 590 | buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; |
591 | } | 591 | } |
592 | |||
593 | #if BB_MMU | ||
594 | pid_t FAST_FUNC xfork(void) | ||
595 | { | ||
596 | pid_t pid; | ||
597 | pid = fork(); | ||
598 | if (pid < 0) /* wtf? */ | ||
599 | bb_perror_msg_and_die("vfork"+1); | ||
600 | return pid; | ||
601 | } | ||
602 | #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) | |||
54 | + (1 << SIGALRM) | 54 | + (1 << SIGALRM) |
55 | , signal_handler); | 55 | , signal_handler); |
56 | 56 | ||
57 | G.helper_pid = vfork(); | 57 | G.helper_pid = xvfork(); |
58 | if (G.helper_pid < 0) | ||
59 | bb_perror_msg_and_die("vfork"); | ||
60 | 58 | ||
61 | i = (!G.helper_pid) * 2; // for parent:0, for child:2 | 59 | i = (!G.helper_pid) * 2; // for parent:0, for child:2 |
62 | close(pipes[i + 1]); // 1 or 3 - closing one write end | 60 | 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) | |||
309 | 309 | ||
310 | static NOINLINE void start_shell_in_child(const char* tty_name) | 310 | static NOINLINE void start_shell_in_child(const char* tty_name) |
311 | { | 311 | { |
312 | int pid = vfork(); | 312 | int pid = xvfork(); |
313 | if (pid < 0) { | ||
314 | bb_perror_msg_and_die("vfork"); | ||
315 | } | ||
316 | if (pid == 0) { | 313 | if (pid == 0) { |
317 | struct termios termchild; | 314 | struct termios termchild; |
318 | char *shell = getenv("SHELL"); | 315 | 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 @@ | |||
20 | static void edit_file(const struct passwd *pas, const char *file) | 20 | static void edit_file(const struct passwd *pas, const char *file) |
21 | { | 21 | { |
22 | const char *ptr; | 22 | const char *ptr; |
23 | int pid = vfork(); | 23 | int pid = xvfork(); |
24 | 24 | ||
25 | if (pid < 0) /* failure */ | ||
26 | bb_perror_msg_and_die("vfork"); | ||
27 | if (pid) { /* parent */ | 25 | if (pid) { /* parent */ |
28 | wait4pid(pid); | 26 | wait4pid(pid); |
29 | return; | 27 | return; |
@@ -51,9 +49,7 @@ static int open_as_user(const struct passwd *pas, const char *file) | |||
51 | pid_t pid; | 49 | pid_t pid; |
52 | char c; | 50 | char c; |
53 | 51 | ||
54 | pid = vfork(); | 52 | pid = xvfork(); |
55 | if (pid < 0) /* ERROR */ | ||
56 | bb_perror_msg_and_die("vfork"); | ||
57 | if (pid) { /* PARENT */ | 53 | if (pid) { /* PARENT */ |
58 | if (wait4pid(pid) == 0) { | 54 | if (wait4pid(pid) == 0) { |
59 | /* exitcode 0: child says it can read */ | 55 | /* 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) | |||
372 | void (*quit_signal)(int); | 372 | void (*quit_signal)(int); |
373 | 373 | ||
374 | resp->elapsed_ms = monotonic_ms(); | 374 | resp->elapsed_ms = monotonic_ms(); |
375 | pid = vfork(); | 375 | pid = xvfork(); |
376 | if (pid < 0) | ||
377 | bb_perror_msg_and_die("vfork"); | ||
378 | if (pid == 0) { | 376 | if (pid == 0) { |
379 | /* Child */ | 377 | /* Child */ |
380 | BB_EXECVP_or_die((char**)cmd); | 378 | 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) | |||
71 | sv1 = argv[optind]; | 71 | sv1 = argv[optind]; |
72 | sv2 = argv[optind + 1]; | 72 | sv2 = argv[optind + 1]; |
73 | #endif | 73 | #endif |
74 | pid = vfork(); | 74 | pid = xvfork(); |
75 | if (pid < 0) | ||
76 | bb_perror_msg_and_die("vfork"); | ||
77 | if (pid == 0) { | 75 | if (pid == 0) { |
78 | /* Child: spawn grandchild and exit */ | 76 | /* Child: spawn grandchild and exit */ |
79 | parent = getppid(); | 77 | 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) | |||
632 | xpiped_pair(outfd); | 632 | xpiped_pair(outfd); |
633 | 633 | ||
634 | /*fflush_all(); - so far we dont use stdio on output */ | 634 | /*fflush_all(); - so far we dont use stdio on output */ |
635 | pid = BB_MMU ? fork() : vfork(); | 635 | pid = BB_MMU ? xfork() : xvfork(); |
636 | if (pid < 0) | ||
637 | bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); | ||
638 | |||
639 | if (pid == 0) { | 636 | if (pid == 0) { |
640 | /* child */ | 637 | /* child */ |
641 | #if !BB_MMU | 638 | #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) | |||
1041 | xpiped_pair(outfd); | 1041 | xpiped_pair(outfd); |
1042 | 1042 | ||
1043 | fflush_all(); | 1043 | fflush_all(); |
1044 | pid = vfork(); | 1044 | pid = xvfork(); |
1045 | 1045 | ||
1046 | switch (pid) { | 1046 | if (pid == 0) { |
1047 | case -1: /* failure */ | 1047 | /* Child */ |
1048 | bb_perror_msg_and_die("vfork"); | ||
1049 | case 0: /* child */ | ||
1050 | /* NB: close _first_, then move fds! */ | 1048 | /* NB: close _first_, then move fds! */ |
1051 | close(infd.wr); | 1049 | close(infd.wr); |
1052 | close(outfd.rd); | 1050 | 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) | |||
1271 | pid = vfork(); | 1271 | pid = vfork(); |
1272 | 1272 | ||
1273 | if (pid < 0) { /* fork error */ | 1273 | if (pid < 0) { /* fork error */ |
1274 | bb_perror_msg("fork"); | 1274 | bb_perror_msg("vfork"+1); |
1275 | sleep(1); | 1275 | sleep(1); |
1276 | restore_sigmask(&omask); | 1276 | restore_sigmask(&omask); |
1277 | maybe_close(accepted_fd); | 1277 | 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) | |||
216 | if (execparam) { | 216 | if (execparam) { |
217 | pid_t pid; | 217 | pid_t pid; |
218 | /* With more than one -l, repeatedly act as server */ | 218 | /* With more than one -l, repeatedly act as server */ |
219 | if (do_listen > 1 && (pid = vfork()) != 0) { | 219 | if (do_listen > 1 && (pid = xvfork()) != 0) { |
220 | /* parent or error */ | 220 | /* parent */ |
221 | if (pid < 0) | ||
222 | bb_perror_msg_and_die("vfork"); | ||
223 | /* prevent zombies */ | 221 | /* prevent zombies */ |
224 | signal(SIGCHLD, SIG_IGN); | 222 | signal(SIGCHLD, SIG_IGN); |
225 | close(cfd); | 223 | 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) | |||
86 | fflush(stdout); | 86 | fflush(stdout); |
87 | switch(pid=fork()) { | 87 | switch(pid=fork()) { |
88 | case -1: | 88 | case -1: |
89 | perror("fork"); | 89 | perror("vfork"+1); |
90 | exit(1); | 90 | exit(1); |
91 | case 0: | 91 | case 0: |
92 | rflen = strlen(getenv("SRCTREE")); | 92 | 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) | |||
3208 | #if !BB_MMU | 3208 | #if !BB_MMU |
3209 | to_free = NULL; | 3209 | to_free = NULL; |
3210 | #endif | 3210 | #endif |
3211 | pid = vfork(); | 3211 | pid = xvfork(); |
3212 | if (pid < 0) | ||
3213 | bb_perror_msg_and_die("vfork"); | ||
3214 | if (pid == 0) { | 3212 | if (pid == 0) { |
3215 | /* child */ | 3213 | /* child */ |
3216 | disable_restore_tty_pgrp_on_exit(); | 3214 | disable_restore_tty_pgrp_on_exit(); |
3217 | pid = BB_MMU ? fork() : vfork(); | 3215 | pid = BB_MMU ? xfork() : xvfork(); |
3218 | if (pid < 0) | ||
3219 | bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); | ||
3220 | if (pid != 0) | 3216 | if (pid != 0) |
3221 | _exit(0); | 3217 | _exit(0); |
3222 | /* grandchild */ | 3218 | /* grandchild */ |
@@ -4450,7 +4446,7 @@ static NOINLINE int run_pipe(struct pipe *pi) | |||
4450 | argv_expanded = NULL; | 4446 | argv_expanded = NULL; |
4451 | if (command->pid < 0) { /* [v]fork failed */ | 4447 | if (command->pid < 0) { /* [v]fork failed */ |
4452 | /* Clearly indicate, was it fork or vfork */ | 4448 | /* Clearly indicate, was it fork or vfork */ |
4453 | bb_perror_msg(BB_MMU ? "fork" : "vfork"); | 4449 | bb_perror_msg(BB_MMU ? "vfork"+1 : "vfork"); |
4454 | } else { | 4450 | } else { |
4455 | pi->alive_cmds++; | 4451 | pi->alive_cmds++; |
4456 | #if ENABLE_HUSH_JOB | 4452 | #if ENABLE_HUSH_JOB |
@@ -5586,10 +5582,7 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p) | |||
5586 | # endif | 5582 | # endif |
5587 | 5583 | ||
5588 | xpipe(channel); | 5584 | xpipe(channel); |
5589 | pid = BB_MMU ? fork() : vfork(); | 5585 | pid = BB_MMU ? xfork() : xvfork(); |
5590 | if (pid < 0) | ||
5591 | bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); | ||
5592 | |||
5593 | if (pid == 0) { /* child */ | 5586 | if (pid == 0) { /* child */ |
5594 | disable_restore_tty_pgrp_on_exit(); | 5587 | disable_restore_tty_pgrp_on_exit(); |
5595 | /* Process substitution is not considered to be usual | 5588 | /* 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) | |||
88 | 88 | ||
89 | /* TODO: SIGWINCH? pass window size changes down to slave? */ | 89 | /* TODO: SIGWINCH? pass window size changes down to slave? */ |
90 | 90 | ||
91 | child_pid = vfork(); | 91 | child_pid = xvfork(); |
92 | if (child_pid < 0) { | ||
93 | bb_perror_msg_and_die("vfork"); | ||
94 | } | ||
95 | 92 | ||
96 | if (child_pid) { | 93 | if (child_pid) { |
97 | /* parent */ | 94 | /* parent */ |