Skip to content

Commit

Permalink
Always mark pipe in pipe-open as inherit-on-exec
Browse files Browse the repository at this point in the history
Since 2cdf406 a lot of file descriptors are opened close-on-exec,
including the pipe that is passed to the child process in a pipe-open.
This is usually fine because a dup2 follows to rename that handle to
stdin/stdout that will set the inherit-on-exec. However, if the pipe
descriptor already has the right value, for example because stdin was
closed, then no dup2 happens and hence it's still marked as
close-on-exec right when we want to perform an exec.

This patch explicitly marks such a handle as inherit-on-exec, to ensure
it will be open for the child process.
  • Loading branch information
Leont committed Dec 15, 2018
1 parent c950d6f commit c6fe5b9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion util.c
Expand Up @@ -2469,8 +2469,10 @@ Perl_my_popen(pTHX_ const char *cmd, const char *mode)
if (p[THAT] != (*mode == 'r')) /* if dup2() didn't close it */
PerlLIO_close(p[THAT]);
}
else
else {
setfd_cloexec_or_inhexec_by_sysfdness(p[THIS]);
PerlLIO_close(p[THAT]);
}
#ifndef OS2
if (doexec) {
#if !defined(HAS_FCNTL) || !defined(F_SETFD)
Expand Down

0 comments on commit c6fe5b9

Please sign in to comment.