This was doing some silly stuff that is not necessary when using

vfork(), so I have simplified it.
This commit is contained in:
Eric Andersen 2003-05-26 18:12:00 +00:00
parent a2d1982841
commit b0cfca7544

View File

@ -83,31 +83,37 @@ extern int run_parts(char **args, const unsigned char test_mode)
if (test_mode & 1) { if (test_mode & 1) {
puts(filename); puts(filename);
} else { } else {
/* exec_errno is common vfork variable */ pid_t pid, wpid;
volatile int exec_errno = 0;
int result; int result;
int pid;
if ((pid = vfork()) < 0) { if ((pid = vfork()) < 0) {
bb_perror_msg_and_die("failed to fork"); bb_perror_msg_and_die("failed to fork");
} else if (!pid) { } else if (pid==0) {
args[0] = filename;
execv(filename, args); execv(filename, args);
exec_errno = errno;
_exit(1); _exit(1);
} }
waitpid(pid, &result, 0); /* Wait for the child process to exit. Since we use vfork
if(exec_errno) { * we shouldn't actually have to do any waiting... */
errno = exec_errno; wpid = wait(&result);
bb_perror_msg_and_die("failed to exec %s", filename); while (wpid > 0) {
} /* Find out who died, make sure it is the right process */
if (WIFEXITED(result) && WEXITSTATUS(result)) { if (pid == wpid) {
bb_perror_msg("%s exited with return code %d", filename, WEXITSTATUS(result)); if (WIFEXITED(result) && WEXITSTATUS(result)) {
exitstatus = 1; bb_perror_msg("%s exited with return code %d", filename, WEXITSTATUS(result));
} else if (WIFSIGNALED(result)) { exitstatus = 1;
bb_perror_msg("%s exited because of uncaught signal %d", filename, WTERMSIG(result)); } else if (WIFSIGNALED(result) && WIFSIGNALED(result)) {
exitstatus = 1; int sig;
sig = WTERMSIG(result);
bb_perror_msg("%s exited because of uncaught signal %d (%s)",
filename, sig, u_signal_names(0, &sig, 1));
exitstatus = 1;
}
break;
} else {
/* Just in case some _other_ random child process exits */
wpid = wait(&result);
}
} }
} }
} }