- if (child_end != STDERR_FILENO) {
- /* dup2() doesn't dup close-on-exec flag */
- ret = dup2(child_end, STDERR_FILENO);
- if (ret < 0)
- WARN("Failed to duplicate stdout fd");
- } else {
- /*
- * The descriptor is already the one we will use.
- * But it must not be marked close-on-exec.
- * Undo the effects.
- */
- ret = fcntl(child_end, F_SETFD, 0);
- if (ret < 0) {
- SYSERROR("Failed to remove FD_CLOEXEC from fd.");
- exit(127);
- }
- }
-
- /*
- * Unblock signals.
- * This is the main/only reason
- * why we do our lousy popen() emulation.
- */
- {
- sigset_t mask;
- sigfillset(&mask);
- sigprocmask(SIG_UNBLOCK, &mask, NULL);
+ /* duplicate stdout */
+ if (pipe_fds[1] != STDOUT_FILENO)
+ ret = dup2(pipe_fds[1], STDOUT_FILENO);
+ else
+ ret = fcntl(pipe_fds[1], F_SETFD, 0);
+ if (ret < 0) {
+ close(pipe_fds[1]);
+ exit(EXIT_FAILURE);