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

This commit is contained in:
Alexandre Julliard 2009-07-01 12:13:46 +02:00
parent 6f68b774d7
commit 887af61219
1 changed files with 10 additions and 4 deletions

View File

@ -1304,12 +1304,18 @@ static int fork_and_exec( const char *filename, const WCHAR *cmdline, const WCHA
if (!env) env = GetEnvironmentStringsW(); if (!env) env = GetEnvironmentStringsW();
#ifdef HAVE_PIPE2
if (pipe2( fd, O_CLOEXEC ) == -1)
#endif
{
if (pipe(fd) == -1) if (pipe(fd) == -1)
{ {
SetLastError( ERROR_TOO_MANY_OPEN_FILES ); SetLastError( ERROR_TOO_MANY_OPEN_FILES );
return -1; return -1;
} }
fcntl( fd[1], F_SETFD, 1 ); /* set close on exec */ fcntl( fd[0], F_SETFD, FD_CLOEXEC );
fcntl( fd[1], F_SETFD, FD_CLOEXEC );
}
if (!(flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS))) if (!(flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS)))
{ {