perl/perl-5.29.5-Always-mark-pipe-in-pipe-open-as-inherit-on-exec.patch

44 lines
1.4 KiB
Diff
Raw Normal View History

From c6fe5b981b942ddabb23ed4b7602067e906e6d88 Mon Sep 17 00:00:00 2001
From: Leon Timmermans <fawaka@gmail.com>
Date: Sat, 15 Dec 2018 19:08:41 +0100
Subject: [PATCH] Always mark pipe in pipe-open as inherit-on-exec
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Since 2cdf406a 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.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
util.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/util.c b/util.c
index a9bf9b8609..99bf4ae2b0 100644
--- a/util.c
+++ b/util.c
@@ -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)
--
2.17.2