aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-05-26 18:12:00 +0000
committerEric Andersen <andersen@codepoet.org>2003-05-26 18:12:00 +0000
commitb0cfca75442293b4b670584d83c39f9cea9f5a8b (patch)
treec05e258028e66a87812e50590318b8951db4db21
parenta2d1982841adf21442c7574e784a45324e7f1db5 (diff)
downloadbusybox-w32-b0cfca75442293b4b670584d83c39f9cea9f5a8b.tar.gz
busybox-w32-b0cfca75442293b4b670584d83c39f9cea9f5a8b.tar.bz2
busybox-w32-b0cfca75442293b4b670584d83c39f9cea9f5a8b.zip
This was doing some silly stuff that is not necessary when using
vfork(), so I have simplified it.
-rw-r--r--libbb/run_parts.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/libbb/run_parts.c b/libbb/run_parts.c
index 58645660b..1cd13f218 100644
--- a/libbb/run_parts.c
+++ b/libbb/run_parts.c
@@ -83,31 +83,37 @@ extern int run_parts(char **args, const unsigned char test_mode)
83 if (test_mode & 1) { 83 if (test_mode & 1) {
84 puts(filename); 84 puts(filename);
85 } else { 85 } else {
86 /* exec_errno is common vfork variable */ 86 pid_t pid, wpid;
87 volatile int exec_errno = 0;
88 int result; 87 int result;
89 int pid;
90 88
91 if ((pid = vfork()) < 0) { 89 if ((pid = vfork()) < 0) {
92 bb_perror_msg_and_die("failed to fork"); 90 bb_perror_msg_and_die("failed to fork");
93 } else if (!pid) { 91 } else if (pid==0) {
94 args[0] = filename;
95 execv(filename, args); 92 execv(filename, args);
96 exec_errno = errno;
97 _exit(1); 93 _exit(1);
98 } 94 }
99 95
100 waitpid(pid, &result, 0); 96 /* Wait for the child process to exit. Since we use vfork
101 if(exec_errno) { 97 * we shouldn't actually have to do any waiting... */
102 errno = exec_errno; 98 wpid = wait(&result);
103 bb_perror_msg_and_die("failed to exec %s", filename); 99 while (wpid > 0) {
104 } 100 /* Find out who died, make sure it is the right process */
105 if (WIFEXITED(result) && WEXITSTATUS(result)) { 101 if (pid == wpid) {
106 bb_perror_msg("%s exited with return code %d", filename, WEXITSTATUS(result)); 102 if (WIFEXITED(result) && WEXITSTATUS(result)) {
107 exitstatus = 1; 103 bb_perror_msg("%s exited with return code %d", filename, WEXITSTATUS(result));
108 } else if (WIFSIGNALED(result)) { 104 exitstatus = 1;
109 bb_perror_msg("%s exited because of uncaught signal %d", filename, WTERMSIG(result)); 105 } else if (WIFSIGNALED(result) && WIFSIGNALED(result)) {
110 exitstatus = 1; 106 int sig;
107 sig = WTERMSIG(result);
108 bb_perror_msg("%s exited because of uncaught signal %d (%s)",
109 filename, sig, u_signal_names(0, &sig, 1));
110 exitstatus = 1;
111 }
112 break;
113 } else {
114 /* Just in case some _other_ random child process exits */
115 wpid = wait(&result);
116 }
111 } 117 }
112 } 118 }
113 } 119 }