aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-01 10:40:41 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-01 10:40:41 +0000
commit3da5572bfa81a63ce66e41b99e9801c47a05bbbf (patch)
tree91e495d81283309948b9f459bbd65c17682431fa
parent148f67af9dac56db4703fb40677630ef559edb57 (diff)
downloadbusybox-w32-3da5572bfa81a63ce66e41b99e9801c47a05bbbf.tar.gz
busybox-w32-3da5572bfa81a63ce66e41b99e9801c47a05bbbf.tar.bz2
busybox-w32-3da5572bfa81a63ce66e41b99e9801c47a05bbbf.zip
*: introduce and use xvfork()
function old new delta time_main 1052 1285 +233 crontab_main 623 856 +233 ifupdown_main 2202 2403 +201 xvfork - 20 +20 passwd_main 1049 1053 +4 grave 1068 1066 -2 script_main 935 921 -14 vfork_or_die 20 - -20 vfork_compressor 206 175 -31 open_as_user 109 - -109 popen2 218 - -218 edit_file 910 690 -220 run_command 268 - -268 ------------------------------------------------------------------------------ (add/remove: 1/4 grow/shrink: 4/4 up/down: 691/-882) Total: -191 bytes
-rw-r--r--archival/libunarchive/open_transformer.c4
-rw-r--r--archival/tar.c4
-rw-r--r--debianutils/start_stop_daemon.c4
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/Kbuild1
-rw-r--r--libbb/vfork_daemon_rexec.c4
-rw-r--r--miscutils/crontab.c8
-rw-r--r--miscutils/time.c4
-rw-r--r--networking/ifupdown.c7
-rw-r--r--networking/sendmail.c11
-rw-r--r--shell/hush.c6
-rw-r--r--util-linux/script.c5
12 files changed, 18 insertions, 42 deletions
diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c
index a6bc62321..16ca6a59c 100644
--- a/archival/libunarchive/open_transformer.c
+++ b/archival/libunarchive/open_transformer.c
@@ -25,9 +25,7 @@ int FAST_FUNC open_transformer(int src_fd,
25 if (pid == -1) 25 if (pid == -1)
26 bb_perror_msg_and_die("can't fork"); 26 bb_perror_msg_and_die("can't fork");
27#else 27#else
28 pid = vfork(); 28 pid = xvfork();
29 if (pid == -1)
30 bb_perror_msg_and_die("can't vfork");
31#endif 29#endif
32 30
33 if (pid == 0) { 31 if (pid == 0) {
diff --git a/archival/tar.c b/archival/tar.c
index 526edb69d..17ac6c55a 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -536,9 +536,7 @@ 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 = vfork(); 539 gzipPid = xvfork();
540 if (gzipPid < 0)
541 bb_perror_msg_and_die("can't vfork");
542 540
543 if (gzipPid == 0) { 541 if (gzipPid == 0) {
544 /* child */ 542 /* child */
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 459fb77e0..f10572ddf 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -404,9 +404,7 @@ 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 = vfork(); 407 pid_t pid = xvfork();
408 if (pid < 0) /* error */
409 bb_perror_msg_and_die("vfork");
410 if (pid != 0) { 408 if (pid != 0) {
411 /* parent */ 409 /* parent */
412 /* why _exit? the child may have changed the stack, 410 /* why _exit? the child may have changed the stack,
diff --git a/include/libbb.h b/include/libbb.h
index 54601f87b..33e465cf4 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -719,6 +719,8 @@ 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
722pid_t xvfork(void) FAST_FUNC;
723
722/* NOMMU friendy fork+exec */ 724/* NOMMU friendy fork+exec */
723pid_t spawn(char **argv) FAST_FUNC; 725pid_t spawn(char **argv) FAST_FUNC;
724pid_t xspawn(char **argv) FAST_FUNC; 726pid_t xspawn(char **argv) FAST_FUNC;
diff --git a/libbb/Kbuild b/libbb/Kbuild
index 5cbecd537..5ace87cad 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -109,6 +109,7 @@ lib-y += xfunc_die.o
109lib-y += xgetcwd.o 109lib-y += xgetcwd.o
110lib-y += xgethostbyname.o 110lib-y += xgethostbyname.o
111lib-y += xreadlink.o 111lib-y += xreadlink.o
112lib-y += xvfork.o
112 113
113# conditionally compiled objects: 114# conditionally compiled objects:
114lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o 115lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 37d4c274e..9baa813a1 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -226,9 +226,7 @@ void FAST_FUNC forkexit_or_rexec(char **argv)
226 if (re_execed) 226 if (re_execed)
227 return; 227 return;
228 228
229 pid = vfork(); 229 pid = xvfork();
230 if (pid < 0) /* wtf? */
231 bb_perror_msg_and_die("vfork");
232 if (pid) /* parent */ 230 if (pid) /* parent */
233 exit(EXIT_SUCCESS); 231 exit(EXIT_SUCCESS);
234 /* child - re-exec ourself */ 232 /* child - re-exec ourself */
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index dc3179dac..4bba9fb44 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -38,10 +38,8 @@ static void change_user(const struct passwd *pas)
38static void edit_file(const struct passwd *pas, const char *file) 38static void edit_file(const struct passwd *pas, const char *file)
39{ 39{
40 const char *ptr; 40 const char *ptr;
41 int pid = vfork(); 41 int pid = xvfork();
42 42
43 if (pid < 0) /* failure */
44 bb_perror_msg_and_die("vfork");
45 if (pid) { /* parent */ 43 if (pid) { /* parent */
46 wait4pid(pid); 44 wait4pid(pid);
47 return; 45 return;
@@ -65,9 +63,7 @@ static int open_as_user(const struct passwd *pas, const char *file)
65 pid_t pid; 63 pid_t pid;
66 char c; 64 char c;
67 65
68 pid = vfork(); 66 pid = xvfork();
69 if (pid < 0) /* ERROR */
70 bb_perror_msg_and_die("vfork");
71 if (pid) { /* PARENT */ 67 if (pid) { /* PARENT */
72 if (wait4pid(pid) == 0) { 68 if (wait4pid(pid) == 0) {
73 /* exitcode 0: child says it can read */ 69 /* exitcode 0: child says it can read */
diff --git a/miscutils/time.c b/miscutils/time.c
index a6d158c53..104548c23 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_us() / 1000; 374 resp->elapsed_ms = monotonic_us() / 1000;
375 pid = vfork(); /* Run CMD as child process. */ 375 pid = xvfork(); /* Run CMD as child process. */
376 if (pid < 0)
377 bb_error_msg_and_die("cannot fork");
378 if (pid == 0) { /* If child. */ 376 if (pid == 0) { /* If child. */
379 /* Don't cast execvp arguments; that causes errors on some systems, 377 /* Don't cast execvp arguments; that causes errors on some systems,
380 versus merely warnings if the cast is left off. */ 378 versus merely warnings if the cast is left off. */
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index c12391863..8caff3f4d 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -1008,12 +1008,9 @@ 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 = vfork(); 1011 pid = xvfork();
1012 1012
1013 switch (pid) { 1013 if (pid == 0) { /* child */
1014 case -1: /* failure */
1015 bb_perror_msg_and_die("vfork");
1016 case 0: /* child */
1017 /* NB: close _first_, then move fds! */ 1014 /* NB: close _first_, then move fds! */
1018 close(infd.wr); 1015 close(infd.wr);
1019 close(outfd.rd); 1016 close(outfd.rd);
diff --git a/networking/sendmail.c b/networking/sendmail.c
index 1c23ca290..c195cc021 100644
--- a/networking/sendmail.c
+++ b/networking/sendmail.c
@@ -120,15 +120,6 @@ static void signal_handler(int signo)
120#undef err 120#undef err
121} 121}
122 122
123/* libbb candidate */
124static 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
132static void launch_helper(const char **argv) 123static void launch_helper(const char **argv)
133{ 124{
134 // setup vanilla unidirectional pipes interchange 125 // setup vanilla unidirectional pipes interchange
@@ -137,7 +128,7 @@ static void launch_helper(const char **argv)
137 128
138 xpipe(pipes); 129 xpipe(pipes);
139 xpipe(pipes+2); 130 xpipe(pipes+2);
140 helper_pid = vfork_or_die(); 131 helper_pid = xvfork();
141 idx = (!helper_pid) * 2; 132 idx = (!helper_pid) * 2;
142 xdup2(pipes[idx], STDIN_FILENO); 133 xdup2(pipes[idx], STDIN_FILENO);
143 xdup2(pipes[3-idx], STDOUT_FILENO); 134 xdup2(pipes[3-idx], STDOUT_FILENO);
diff --git a/shell/hush.c b/shell/hush.c
index 72186f970..59d8f3f99 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3096,9 +3096,11 @@ 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 ? fork() : vfork(); 3099 pid = BB_MMU ? fork() : xvfork();
3100#if BB_MMU
3100 if (pid < 0) 3101 if (pid < 0)
3101 bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork"); 3102 bb_perror_msg_and_die("fork");
3103#endif
3102 if (pid == 0) { /* child */ 3104 if (pid == 0) { /* child */
3103 if (ENABLE_HUSH_JOB) 3105 if (ENABLE_HUSH_JOB)
3104 die_sleep = 0; /* let nofork's xfuncs die */ 3106 die_sleep = 0; /* let nofork's xfuncs die */
diff --git a/util-linux/script.c b/util-linux/script.c
index e70294e6c..a6c1ab88a 100644
--- a/util-linux/script.c
+++ b/util-linux/script.c
@@ -87,10 +87,7 @@ 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 = vfork(); 90 child_pid = xvfork();
91 if (child_pid < 0) {
92 bb_perror_msg_and_die("vfork");
93 }
94 91
95 if (child_pid) { 92 if (child_pid) {
96 /* parent */ 93 /* parent */