diff --git a/scheduler/thread.c b/scheduler/thread.c index 591723eef4c..da903f95bcb 100644 --- a/scheduler/thread.c +++ b/scheduler/thread.c @@ -9,9 +9,6 @@ #include #include #include -#ifdef HAVE_SYS_SOCKET_H -# include -#endif #ifdef HAVE_SYS_MMAN_H #include #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 */ diff --git a/server/thread.c b/server/thread.c index 39cd5cfd76a..5932644a849 100644 --- a/server/thread.c +++ b/server/thread.c @@ -16,6 +16,9 @@ #include #endif #include +#ifdef HAVE_SYS_SOCKET_H +# include +#endif #include #include #include @@ -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 */