revert last two commits. vfork cannot be used in subroutine,
it trashes stack on return
This commit is contained in:
@@ -1008,9 +1008,12 @@ static int popen2(FILE **in, FILE **out, char *command, char *param)
|
||||
xpiped_pair(outfd);
|
||||
|
||||
fflush(NULL);
|
||||
pid = xvfork();
|
||||
pid = vfork();
|
||||
|
||||
if (pid == 0) { /* child */
|
||||
switch (pid) {
|
||||
case -1: /* failure */
|
||||
bb_perror_msg_and_die("vfork");
|
||||
case 0: /* child */
|
||||
/* NB: close _first_, then move fds! */
|
||||
close(infd.wr);
|
||||
close(outfd.rd);
|
||||
|
@@ -1303,7 +1303,7 @@ int inetd_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
pid = vfork();
|
||||
|
||||
if (pid < 0) { /* fork error */
|
||||
bb_perror_msg(BB_MMU ? "vfork" + 1 : "vfork");
|
||||
bb_perror_msg("fork");
|
||||
sleep(1);
|
||||
restore_sigmask(&omask);
|
||||
maybe_close(accepted_fd);
|
||||
|
@@ -120,6 +120,15 @@ static void signal_handler(int signo)
|
||||
#undef err
|
||||
}
|
||||
|
||||
/* libbb candidate */
|
||||
static pid_t vfork_or_die(void)
|
||||
{
|
||||
pid_t pid = vfork();
|
||||
if (pid < 0)
|
||||
bb_perror_msg_and_die("vfork");
|
||||
return pid;
|
||||
}
|
||||
|
||||
static void launch_helper(const char **argv)
|
||||
{
|
||||
// setup vanilla unidirectional pipes interchange
|
||||
@@ -128,7 +137,7 @@ static void launch_helper(const char **argv)
|
||||
|
||||
xpipe(pipes);
|
||||
xpipe(pipes+2);
|
||||
helper_pid = xvfork();
|
||||
helper_pid = vfork_or_die();
|
||||
idx = (!helper_pid) * 2;
|
||||
xdup2(pipes[idx], STDIN_FILENO);
|
||||
xdup2(pipes[3-idx], STDOUT_FILENO);
|
||||
|
Reference in New Issue
Block a user