diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-01 15:59:42 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-01 15:59:42 +0000 |
commit | 82604e973085f91f1b99cacea08963d0d1468084 (patch) | |
tree | 2de05bb2a6943ca6be0cc46f36e5fb07099aef40 | |
parent | b111917972c1398ef96ef2d388c6c4ba57a8e9f7 (diff) | |
download | busybox-w32-82604e973085f91f1b99cacea08963d0d1468084.tar.gz busybox-w32-82604e973085f91f1b99cacea08963d0d1468084.tar.bz2 busybox-w32-82604e973085f91f1b99cacea08963d0d1468084.zip |
revert last two commits. vfork cannot be used in subroutine,
it trashes stack on return
-rw-r--r-- | archival/libunarchive/open_transformer.c | 11 | ||||
-rw-r--r-- | archival/tar.c | 4 | ||||
-rw-r--r-- | debianutils/start_stop_daemon.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | libbb/Kbuild | 1 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 8 | ||||
-rw-r--r-- | libbb/xvfork.c | 28 | ||||
-rw-r--r-- | miscutils/crontab.c | 8 | ||||
-rw-r--r-- | miscutils/time.c | 4 | ||||
-rw-r--r-- | networking/ifupdown.c | 7 | ||||
-rw-r--r-- | networking/inetd.c | 2 | ||||
-rw-r--r-- | networking/sendmail.c | 11 | ||||
-rw-r--r-- | shell/hush.c | 6 | ||||
-rw-r--r-- | util-linux/mount.c | 1 | ||||
-rw-r--r-- | util-linux/script.c | 5 |
15 files changed, 55 insertions, 50 deletions
diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c index 0738e3db1..a6bc62321 100644 --- a/archival/libunarchive/open_transformer.c +++ b/archival/libunarchive/open_transformer.c | |||
@@ -20,7 +20,16 @@ int FAST_FUNC open_transformer(int src_fd, | |||
20 | 20 | ||
21 | xpiped_pair(fd_pipe); | 21 | xpiped_pair(fd_pipe); |
22 | 22 | ||
23 | pid = BB_MMU ? xfork() : xvfork(); | 23 | #if BB_MMU |
24 | pid = fork(); | ||
25 | if (pid == -1) | ||
26 | bb_perror_msg_and_die("can't fork"); | ||
27 | #else | ||
28 | pid = vfork(); | ||
29 | if (pid == -1) | ||
30 | bb_perror_msg_and_die("can't vfork"); | ||
31 | #endif | ||
32 | |||
24 | if (pid == 0) { | 33 | if (pid == 0) { |
25 | /* child process */ | 34 | /* child process */ |
26 | close(fd_pipe.rd); /* We don't want to read from the parent */ | 35 | close(fd_pipe.rd); /* We don't want to read from the parent */ |
diff --git a/archival/tar.c b/archival/tar.c index 17ac6c55a..526edb69d 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -536,7 +536,9 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip) | |||
536 | (void) &zip_exec; | 536 | (void) &zip_exec; |
537 | #endif | 537 | #endif |
538 | 538 | ||
539 | gzipPid = xvfork(); | 539 | gzipPid = vfork(); |
540 | if (gzipPid < 0) | ||
541 | bb_perror_msg_and_die("can't vfork"); | ||
540 | 542 | ||
541 | if (gzipPid == 0) { | 543 | if (gzipPid == 0) { |
542 | /* child */ | 544 | /* child */ |
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index f10572ddf..459fb77e0 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -404,7 +404,9 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
404 | /* DAEMON_DEVNULL_STDIO is superfluous - | 404 | /* DAEMON_DEVNULL_STDIO is superfluous - |
405 | * it's always done by bb_daemonize() */ | 405 | * it's always done by bb_daemonize() */ |
406 | #else | 406 | #else |
407 | pid_t pid = xvfork(); | 407 | pid_t pid = vfork(); |
408 | if (pid < 0) /* error */ | ||
409 | bb_perror_msg_and_die("vfork"); | ||
408 | if (pid != 0) { | 410 | if (pid != 0) { |
409 | /* parent */ | 411 | /* parent */ |
410 | /* why _exit? the child may have changed the stack, | 412 | /* why _exit? the child may have changed the stack, |
diff --git a/include/libbb.h b/include/libbb.h index 67eef6dbb..54601f87b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -719,11 +719,6 @@ int bb_execvp(const char *file, char *const argv[]) FAST_FUNC; | |||
719 | #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__) | 719 | #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__) |
720 | #endif | 720 | #endif |
721 | 721 | ||
722 | #if BB_MMU | ||
723 | pid_t xfork(void) FAST_FUNC; | ||
724 | #endif | ||
725 | pid_t xvfork(void) FAST_FUNC; | ||
726 | |||
727 | /* NOMMU friendy fork+exec */ | 722 | /* NOMMU friendy fork+exec */ |
728 | pid_t spawn(char **argv) FAST_FUNC; | 723 | pid_t spawn(char **argv) FAST_FUNC; |
729 | pid_t xspawn(char **argv) FAST_FUNC; | 724 | pid_t xspawn(char **argv) FAST_FUNC; |
diff --git a/libbb/Kbuild b/libbb/Kbuild index 5ace87cad..5cbecd537 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
@@ -109,7 +109,6 @@ lib-y += xfunc_die.o | |||
109 | lib-y += xgetcwd.o | 109 | lib-y += xgetcwd.o |
110 | lib-y += xgethostbyname.o | 110 | lib-y += xgethostbyname.o |
111 | lib-y += xreadlink.o | 111 | lib-y += xreadlink.o |
112 | lib-y += xvfork.o | ||
113 | 112 | ||
114 | # conditionally compiled objects: | 113 | # conditionally compiled objects: |
115 | lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o | 114 | lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o |
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 989e9b841..37d4c274e 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -226,7 +226,9 @@ void FAST_FUNC forkexit_or_rexec(char **argv) | |||
226 | if (re_execed) | 226 | if (re_execed) |
227 | return; | 227 | return; |
228 | 228 | ||
229 | pid = xvfork(); | 229 | pid = vfork(); |
230 | if (pid < 0) /* wtf? */ | ||
231 | bb_perror_msg_and_die("vfork"); | ||
230 | if (pid) /* parent */ | 232 | if (pid) /* parent */ |
231 | exit(EXIT_SUCCESS); | 233 | exit(EXIT_SUCCESS); |
232 | /* child - re-exec ourself */ | 234 | /* child - re-exec ourself */ |
@@ -238,7 +240,9 @@ void FAST_FUNC forkexit_or_rexec(char **argv) | |||
238 | void FAST_FUNC forkexit_or_rexec(void) | 240 | void FAST_FUNC forkexit_or_rexec(void) |
239 | { | 241 | { |
240 | pid_t pid; | 242 | pid_t pid; |
241 | pid = xfork(); | 243 | pid = fork(); |
244 | if (pid < 0) /* wtf? */ | ||
245 | bb_perror_msg_and_die("fork"); | ||
242 | if (pid) /* parent */ | 246 | if (pid) /* parent */ |
243 | exit(EXIT_SUCCESS); | 247 | exit(EXIT_SUCCESS); |
244 | /* child */ | 248 | /* child */ |
diff --git a/libbb/xvfork.c b/libbb/xvfork.c deleted file mode 100644 index 3fbd0c1ed..000000000 --- a/libbb/xvfork.c +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) 2007 Denys Vlasenko | ||
6 | * | ||
7 | * Licensed under GPL version 2, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | #include "libbb.h" | ||
11 | |||
12 | pid_t FAST_FUNC xvfork(void) | ||
13 | { | ||
14 | pid_t pid = vfork(); | ||
15 | if (pid < 0) | ||
16 | bb_perror_msg_and_die("vfork"); | ||
17 | return pid; | ||
18 | } | ||
19 | |||
20 | #if BB_MMU | ||
21 | pid_t FAST_FUNC xfork(void) | ||
22 | { | ||
23 | pid_t pid = fork(); | ||
24 | if (pid < 0) | ||
25 | bb_perror_msg_and_die("vfork" + 1); | ||
26 | return pid; | ||
27 | } | ||
28 | #endif | ||
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 4bba9fb44..dc3179dac 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -38,8 +38,10 @@ static void change_user(const struct passwd *pas) | |||
38 | static void edit_file(const struct passwd *pas, const char *file) | 38 | static void edit_file(const struct passwd *pas, const char *file) |
39 | { | 39 | { |
40 | const char *ptr; | 40 | const char *ptr; |
41 | int pid = xvfork(); | 41 | int pid = vfork(); |
42 | 42 | ||
43 | if (pid < 0) /* failure */ | ||
44 | bb_perror_msg_and_die("vfork"); | ||
43 | if (pid) { /* parent */ | 45 | if (pid) { /* parent */ |
44 | wait4pid(pid); | 46 | wait4pid(pid); |
45 | return; | 47 | return; |
@@ -63,7 +65,9 @@ static int open_as_user(const struct passwd *pas, const char *file) | |||
63 | pid_t pid; | 65 | pid_t pid; |
64 | char c; | 66 | char c; |
65 | 67 | ||
66 | pid = xvfork(); | 68 | pid = vfork(); |
69 | if (pid < 0) /* ERROR */ | ||
70 | bb_perror_msg_and_die("vfork"); | ||
67 | if (pid) { /* PARENT */ | 71 | if (pid) { /* PARENT */ |
68 | if (wait4pid(pid) == 0) { | 72 | if (wait4pid(pid) == 0) { |
69 | /* exitcode 0: child says it can read */ | 73 | /* exitcode 0: child says it can read */ |
diff --git a/miscutils/time.c b/miscutils/time.c index 104548c23..a6d158c53 100644 --- a/miscutils/time.c +++ b/miscutils/time.c | |||
@@ -372,7 +372,9 @@ 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_us() / 1000; | 374 | resp->elapsed_ms = monotonic_us() / 1000; |
375 | pid = xvfork(); /* Run CMD as child process. */ | 375 | pid = vfork(); /* Run CMD as child process. */ |
376 | if (pid < 0) | ||
377 | bb_error_msg_and_die("cannot fork"); | ||
376 | if (pid == 0) { /* If child. */ | 378 | if (pid == 0) { /* If child. */ |
377 | /* Don't cast execvp arguments; that causes errors on some systems, | 379 | /* Don't cast execvp arguments; that causes errors on some systems, |
378 | versus merely warnings if the cast is left off. */ | 380 | versus merely warnings if the cast is left off. */ |
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 8caff3f4d..c12391863 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -1008,9 +1008,12 @@ static int popen2(FILE **in, FILE **out, char *command, char *param) | |||
1008 | xpiped_pair(outfd); | 1008 | xpiped_pair(outfd); |
1009 | 1009 | ||
1010 | fflush(NULL); | 1010 | fflush(NULL); |
1011 | pid = xvfork(); | 1011 | pid = vfork(); |
1012 | 1012 | ||
1013 | if (pid == 0) { /* child */ | 1013 | switch (pid) { |
1014 | case -1: /* failure */ | ||
1015 | bb_perror_msg_and_die("vfork"); | ||
1016 | case 0: /* child */ | ||
1014 | /* NB: close _first_, then move fds! */ | 1017 | /* NB: close _first_, then move fds! */ |
1015 | close(infd.wr); | 1018 | close(infd.wr); |
1016 | close(outfd.rd); | 1019 | close(outfd.rd); |
diff --git a/networking/inetd.c b/networking/inetd.c index 0028078db..08c09953b 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -1303,7 +1303,7 @@ int inetd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
1303 | pid = vfork(); | 1303 | pid = vfork(); |
1304 | 1304 | ||
1305 | if (pid < 0) { /* fork error */ | 1305 | if (pid < 0) { /* fork error */ |
1306 | bb_perror_msg(BB_MMU ? "vfork" + 1 : "vfork"); | 1306 | bb_perror_msg("fork"); |
1307 | sleep(1); | 1307 | sleep(1); |
1308 | restore_sigmask(&omask); | 1308 | restore_sigmask(&omask); |
1309 | maybe_close(accepted_fd); | 1309 | maybe_close(accepted_fd); |
diff --git a/networking/sendmail.c b/networking/sendmail.c index c195cc021..1c23ca290 100644 --- a/networking/sendmail.c +++ b/networking/sendmail.c | |||
@@ -120,6 +120,15 @@ static void signal_handler(int signo) | |||
120 | #undef err | 120 | #undef err |
121 | } | 121 | } |
122 | 122 | ||
123 | /* libbb candidate */ | ||
124 | static pid_t vfork_or_die(void) | ||
125 | { | ||
126 | pid_t pid = vfork(); | ||
127 | if (pid < 0) | ||
128 | bb_perror_msg_and_die("vfork"); | ||
129 | return pid; | ||
130 | } | ||
131 | |||
123 | static void launch_helper(const char **argv) | 132 | static void launch_helper(const char **argv) |
124 | { | 133 | { |
125 | // setup vanilla unidirectional pipes interchange | 134 | // setup vanilla unidirectional pipes interchange |
@@ -128,7 +137,7 @@ static void launch_helper(const char **argv) | |||
128 | 137 | ||
129 | xpipe(pipes); | 138 | xpipe(pipes); |
130 | xpipe(pipes+2); | 139 | xpipe(pipes+2); |
131 | helper_pid = xvfork(); | 140 | helper_pid = vfork_or_die(); |
132 | idx = (!helper_pid) * 2; | 141 | idx = (!helper_pid) * 2; |
133 | xdup2(pipes[idx], STDIN_FILENO); | 142 | xdup2(pipes[idx], STDIN_FILENO); |
134 | xdup2(pipes[3-idx], STDOUT_FILENO); | 143 | xdup2(pipes[3-idx], STDOUT_FILENO); |
diff --git a/shell/hush.c b/shell/hush.c index 27fab0d1b..72186f970 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1902,7 +1902,7 @@ static int run_pipe(struct pipe *pi) | |||
1902 | #endif | 1902 | #endif |
1903 | if (child->pid < 0) { /* [v]fork failed */ | 1903 | if (child->pid < 0) { /* [v]fork failed */ |
1904 | /* Clearly indicate, was it fork or vfork */ | 1904 | /* Clearly indicate, was it fork or vfork */ |
1905 | bb_perror_msg(BB_MMU ? "vfork" + 1 : "vfork"); | 1905 | bb_perror_msg(BB_MMU ? "fork" : "vfork"); |
1906 | } else { | 1906 | } else { |
1907 | pi->alive_progs++; | 1907 | pi->alive_progs++; |
1908 | #if ENABLE_HUSH_JOB | 1908 | #if ENABLE_HUSH_JOB |
@@ -3096,7 +3096,9 @@ static FILE *generate_stream_from_list(struct pipe *head) | |||
3096 | * huge=`cat TESTFILE` # will block here forever | 3096 | * huge=`cat TESTFILE` # will block here forever |
3097 | * echo OK | 3097 | * echo OK |
3098 | */ | 3098 | */ |
3099 | pid = BB_MMU ? xfork() : xvfork(); | 3099 | pid = BB_MMU ? fork() : vfork(); |
3100 | if (pid < 0) | ||
3101 | bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); | ||
3100 | if (pid == 0) { /* child */ | 3102 | if (pid == 0) { /* child */ |
3101 | if (ENABLE_HUSH_JOB) | 3103 | if (ENABLE_HUSH_JOB) |
3102 | die_sleep = 0; /* let nofork's xfuncs die */ | 3104 | die_sleep = 0; /* let nofork's xfuncs die */ |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 664d24fd8..3b77af728 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -890,7 +890,6 @@ get_mountport(struct pmap *pm_mnt, | |||
890 | } | 890 | } |
891 | 891 | ||
892 | #if BB_MMU | 892 | #if BB_MMU |
893 | /* Unlike bb_daemonize(), parent does NOT exit here, but returns 0 */ | ||
894 | static int daemonize(void) | 893 | static int daemonize(void) |
895 | { | 894 | { |
896 | int fd; | 895 | int fd; |
diff --git a/util-linux/script.c b/util-linux/script.c index a6c1ab88a..e70294e6c 100644 --- a/util-linux/script.c +++ b/util-linux/script.c | |||
@@ -87,7 +87,10 @@ int script_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
87 | 87 | ||
88 | /* TODO: SIGWINCH? pass window size changes down to slave? */ | 88 | /* TODO: SIGWINCH? pass window size changes down to slave? */ |
89 | 89 | ||
90 | child_pid = xvfork(); | 90 | child_pid = vfork(); |
91 | if (child_pid < 0) { | ||
92 | bb_perror_msg_and_die("vfork"); | ||
93 | } | ||
91 | 94 | ||
92 | if (child_pid) { | 95 | if (child_pid) { |
93 | /* parent */ | 96 | /* parent */ |