ntdll: 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:34 +02:00
parent 3269d8c726
commit 6f68b774d7
6 changed files with 36 additions and 9 deletions

2
configure vendored
View File

@ -18349,6 +18349,7 @@ CFLAGS="$CFLAGS $BUILTINFLAG"
for ac_func in \
@ -18388,6 +18389,7 @@ for ac_func in \
memmove \
mmap \
pclose \
pipe2 \
poll \
popen \
prctl \

View File

@ -1610,6 +1610,7 @@ AC_CHECK_FUNCS(\
memmove \
mmap \
pclose \
pipe2 \
poll \
popen \
prctl \

View File

@ -85,6 +85,7 @@ extern void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset
extern int server_remove_fd_from_cache( HANDLE handle );
extern int server_get_unix_fd( HANDLE handle, unsigned int access, int *unix_fd,
int *needs_close, enum server_fd_type *type, unsigned int *options );
extern int server_pipe( int fd[2] );
/* security descriptors */
NTSTATUS NTDLL_create_struct_sd(PSECURITY_DESCRIPTOR nt_sd, struct security_descriptor **server_sd,

View File

@ -662,6 +662,32 @@ void CDECL wine_server_release_fd( HANDLE handle, int unix_fd )
}
/***********************************************************************
* server_pipe
*
* Create a pipe for communicating with the server.
*/
int server_pipe( int fd[2] )
{
int ret;
#ifdef HAVE_PIPE2
static int have_pipe2 = 1;
if (have_pipe2)
{
if (!(ret = pipe2( fd, O_CLOEXEC ))) return ret;
if (errno == ENOSYS || errno == EINVAL) have_pipe2 = 0; /* don't try again */
}
#endif
if (!(ret = pipe( fd )))
{
fcntl( fd[0], F_SETFD, FD_CLOEXEC );
fcntl( fd[1], F_SETFD, FD_CLOEXEC );
}
return ret;
}
/***********************************************************************
* start_server
*
@ -1029,18 +1055,13 @@ size_t server_init_thread( void *entry_point )
sigaction( SIGCHLD, &sig_act, NULL );
/* create the server->client communication pipes */
if (pipe( reply_pipe ) == -1) server_protocol_perror( "pipe" );
if (pipe( ntdll_get_thread_data()->wait_fd ) == -1) server_protocol_perror( "pipe" );
if (server_pipe( reply_pipe ) == -1) server_protocol_perror( "pipe" );
if (server_pipe( ntdll_get_thread_data()->wait_fd ) == -1) server_protocol_perror( "pipe" );
wine_server_send_fd( reply_pipe[1] );
wine_server_send_fd( ntdll_get_thread_data()->wait_fd[1] );
ntdll_get_thread_data()->reply_fd = reply_pipe[0];
close( reply_pipe[1] );
/* set close on exec flag */
fcntl( ntdll_get_thread_data()->reply_fd, F_SETFD, 1 );
fcntl( ntdll_get_thread_data()->wait_fd[0], F_SETFD, 1 );
fcntl( ntdll_get_thread_data()->wait_fd[1], F_SETFD, 1 );
SERVER_START_REQ( init_thread )
{
req->unix_pid = getpid();

View File

@ -488,8 +488,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *
return result.create_thread.status;
}
if (pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
if (server_pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
wine_server_send_fd( request_pipe[0] );
SERVER_START_REQ( new_thread )

View File

@ -552,6 +552,9 @@
/* Define to 1 if the system has the type `pid_t'. */
#undef HAVE_PID_T
/* Define to 1 if you have the `pipe2' function. */
#undef HAVE_PIPE2
/* Define to 1 if you have the <png.h> header file. */
#undef HAVE_PNG_H