Alexandre Julliard : kernel32: Avoid the close-on-exec race with pipe() on kernels that support pipe2().

Alexandre Julliard julliard at winehq.org
Wed Jul 1 09:28:11 CDT 2009


Module: wine
Branch: master
Commit: 887af612190f3c14d6f8513bf405759b98073e01
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=887af612190f3c14d6f8513bf405759b98073e01

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Jul  1 12:13:46 2009 +0200

kernel32: Avoid the close-on-exec race with pipe() on kernels that support pipe2().

---

 dlls/kernel32/process.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 83d1aa5..6fde35b 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -1304,12 +1304,18 @@ static int fork_and_exec( const char *filename, const WCHAR *cmdline, const WCHA
 
     if (!env) env = GetEnvironmentStringsW();
 
-    if (pipe(fd) == -1)
+#ifdef HAVE_PIPE2
+    if (pipe2( fd, O_CLOEXEC ) == -1)
+#endif
     {
-        SetLastError( ERROR_TOO_MANY_OPEN_FILES );
-        return -1;
+        if (pipe(fd) == -1)
+        {
+            SetLastError( ERROR_TOO_MANY_OPEN_FILES );
+            return -1;
+        }
+        fcntl( fd[0], F_SETFD, FD_CLOEXEC );
+        fcntl( fd[1], F_SETFD, FD_CLOEXEC );
     }
-    fcntl( fd[1], F_SETFD, 1 );  /* set close on exec */
 
     if (!(flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS)))
     {




More information about the wine-cvs mailing list