Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
spawn: reshuffle code to get proper stdin for spawned process
  • Loading branch information
perexg committed Nov 17, 2014
1 parent 29ccb30 commit fc7e0f4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/spawn.c
Expand Up @@ -335,19 +335,18 @@ spawn_and_give_stdout(const char *prog, char *argv[], int *rd, int redir_stderr)
}

if(p == 0) {
close(0);
close(2);
close(fd[0]);
dup2(fd[1], 1);
close(fd[1]);

f = open("/dev/null", O_RDWR);
if(f == -1) {
spawn_error("pid %d cannot open /dev/null for redirect %s -- %s",
getpid(), prog, strerror(errno));
exit(1);
}

close(0);
close(2);
close(fd[0]);
dup2(fd[1], 1);
close(fd[1]);
dup2(f, 0);
dup2(redir_stderr ? spawn_pipe_error.wr : f, 2);
close(f);
Expand Down

0 comments on commit fc7e0f4

Please sign in to comment.