Moved allocation of the socket pair for a new thread to the server.

This commit is contained in:
Alexandre Julliard 2000-01-04 02:40:22 +00:00
parent 79b1ec8290
commit 95e7acb95d
2 changed files with 21 additions and 26 deletions

View File

@ -9,9 +9,6 @@
#include <assert.h>
#include <fcntl.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
@ -213,7 +210,6 @@ TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16,
LPSECURITY_ATTRIBUTES sa, int *server_handle )
{
struct new_thread_request *req = get_req_buffer();
int fd[2];
HANDLE cleanup_object;
TEB *teb = VirtualAlloc(0, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
@ -233,24 +229,15 @@ TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16,
teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, SEGMENT_DATA, TRUE, FALSE );
if (!teb->teb_sel) goto error;
/* Create the socket pair for server communication */
if (socketpair( AF_UNIX, SOCK_STREAM, 0, fd ) == -1)
{
SetLastError( ERROR_TOO_MANY_OPEN_FILES ); /* FIXME */
goto error;
}
teb->socket = fd[0];
fcntl( fd[0], F_SETFD, 1 ); /* set close on exec flag */
/* Create the thread on the server side */
req->pid = teb->process->server_pid;
req->suspend = ((flags & CREATE_SUSPENDED) != 0);
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
if (server_call_fd( REQ_NEW_THREAD, fd[1], NULL )) goto error;
if (server_call_fd( REQ_NEW_THREAD, -1, &teb->socket )) goto error;
teb->tid = req->tid;
*server_handle = req->handle;
fcntl( teb->socket, F_SETFD, 1 ); /* set close on exec flag */
/* Do the rest of the initialization */

View File

@ -16,6 +16,9 @@
#include <sys/mman.h>
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#include <sys/uio.h>
#include <unistd.h>
#include <stdarg.h>
@ -546,24 +549,29 @@ DECL_HANDLER(new_thread)
{
struct thread *thread;
struct process *process;
int sock[2];
if ((process = get_process_from_id( req->pid )))
if (!(process = get_process_from_id( req->pid ))) return;
if (socketpair( AF_UNIX, SOCK_STREAM, 0, sock ) != -1)
{
if ((fd = dup(fd)) != -1)
if ((thread = create_thread( sock[0], process, req->suspend )))
{
if ((thread = create_thread( fd, process, req->suspend )))
req->tid = thread;
if ((req->handle = alloc_handle( current->process, thread,
THREAD_ALL_ACCESS, req->inherit )) != -1)
{
req->tid = thread;
if ((req->handle = alloc_handle( current->process, thread,
THREAD_ALL_ACCESS, req->inherit )) == -1)
release_object( thread );
/* else will be released when the thread gets killed */
set_reply_fd( current, sock[1] );
release_object( process );
/* thread object will be released when the thread gets killed */
return;
}
else close( fd );
release_object( thread );
}
else file_set_error();
release_object( process );
close( sock[1] );
}
else file_set_error();
release_object( process );
}
/* retrieve the thread buffer file descriptor */