Use the new send_fd mechanism for the set_console_fd server request.

This commit is contained in:
Alexandre Julliard 2001-03-22 19:35:27 +00:00
parent 9fd15a9f2f
commit a5a872efca
5 changed files with 31 additions and 54 deletions

View File

@ -757,8 +757,8 @@ struct set_console_fd_request
{
REQUEST_HEADER; /* request header */
IN handle_t handle; /* handle to the console */
IN handle_t handle_in; /* handle of file to use as input */
IN handle_t handle_out; /* handle of file to use as output */
IN int fd_in; /* file descriptor to use as input */
IN int fd_out; /* file descriptor to use as output */
IN int pid; /* pid of xterm (hack) */
};
@ -1611,7 +1611,7 @@ union generic_request
struct async_result_request async_result;
};
#define SERVER_PROTOCOL_VERSION 42
#define SERVER_PROTOCOL_VERSION 43
/* ### make_requests end ### */
/* Everything above this line is generated automatically by tools/make_requests */

View File

@ -229,20 +229,18 @@ void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
*/
static void set_console_handles( HANDLE console )
{
HANDLE in = FILE_DupUnixHandle( 0, GENERIC_READ );
HANDLE out = FILE_DupUnixHandle( 1, GENERIC_WRITE );
wine_server_send_fd( 0 );
wine_server_send_fd( 1 );
SERVER_START_REQ( set_console_fd )
{
req->handle = console;
req->handle_in = in;
req->handle_out = out;
req->pid = 0;
req->handle = console;
req->fd_in = 0;
req->fd_out = 1;
req->pid = 0;
SERVER_CALL();
}
SERVER_END_REQ;
NtClose( in );
NtClose( out );
}

View File

@ -477,36 +477,16 @@ DECL_HANDLER(get_console_info)
/* set a console fd */
DECL_HANDLER(set_console_fd)
{
struct object *obj_in, *obj_out;
int fd_in, fd_out;
int fd_out, fd_in = thread_get_inflight_fd( current, req->fd_in );
if (!(obj_in = get_handle_obj( current->process, req->handle_in, GENERIC_READ, NULL )))
return;
if ((fd_in = dup(obj_in->ops->get_fd( obj_in ))) == -1)
{
release_object( obj_in );
return;
}
release_object( obj_in );
if (req->fd_out == req->fd_in) fd_out = dup( fd_in );
else fd_out = thread_get_inflight_fd( current, req->fd_out );
if (!(obj_out = get_handle_obj( current->process, req->handle_out, GENERIC_WRITE, NULL )))
{
close( fd_in );
return;
}
if ((fd_out = dup(obj_out->ops->get_fd( obj_out ))) == -1)
{
release_object( obj_out );
close( fd_in );
return;
}
release_object( obj_out );
if (fd_in == -1 || fd_out == -1) set_error( STATUS_INVALID_HANDLE );
else if (set_console_fd( req->handle, fd_in, fd_out, req->pid )) return;
if (!set_console_fd( req->handle, fd_in, fd_out, req->pid ))
{
close( fd_out );
close( fd_in );
}
if (fd_in != -1) close( fd_in );
if (fd_out != -1) close( fd_out );
}
/* get a console mode (input or output) */

View File

@ -869,8 +869,8 @@ static void dump_open_console_reply( const struct open_console_request *req )
static void dump_set_console_fd_request( const struct set_console_fd_request *req )
{
fprintf( stderr, " handle=%d,", req->handle );
fprintf( stderr, " handle_in=%d,", req->handle_in );
fprintf( stderr, " handle_out=%d,", req->handle_out );
fprintf( stderr, " fd_in=%d,", req->fd_in );
fprintf( stderr, " fd_out=%d,", req->fd_out );
fprintf( stderr, " pid=%d", req->pid );
}

View File

@ -42,7 +42,6 @@
#include "wine/winuser16.h"
#include "wine/keyboard16.h"
#include "thread.h"
#include "file.h"
#include "winerror.h"
#include "wincon.h"
#include "heap.h"
@ -580,7 +579,6 @@ static BOOL CONSOLE_make_complex(HANDLE handle)
char buf[256];
char c = '\0';
int i,xpid,master,slave;
HANDLE pty_handle;
if (CONSOLE_GetPid( handle )) return TRUE; /* already complex */
@ -605,36 +603,37 @@ static BOOL CONSOLE_make_complex(HANDLE handle)
ERR("error creating AllocConsole xterm\n");
exit(1);
}
pty_handle = FILE_DupUnixHandle( slave, GENERIC_READ | GENERIC_WRITE );
close( master );
close( slave );
if (!pty_handle) return FALSE;
/* most xterms like to print their window ID when used with -S;
* read it and continue before the user has a chance...
*/
for (i = 0; i < 10000; i++)
{
BOOL ok = ReadFile( pty_handle, &c, 1, NULL, NULL );
if (!ok && !c) usleep(100); /* wait for xterm to be created */
else if (c == '\n') break;
if (read( slave, &c, 1 ) == 1)
{
if (c == '\n') break;
}
else usleep(100); /* wait for xterm to be created */
}
if (i == 10000)
{
ERR("can't read xterm WID\n");
CloseHandle( pty_handle );
close( slave );
return FALSE;
}
wine_server_send_fd( slave );
SERVER_START_REQ( set_console_fd )
{
req->handle = handle;
req->handle_in = pty_handle;
req->handle_out = pty_handle;
req->pid = xpid;
req->handle = handle;
req->fd_in = slave;
req->fd_out = slave;
req->pid = xpid;
SERVER_CALL();
close( slave );
}
SERVER_END_REQ;
CloseHandle( pty_handle );
/* enable mouseclicks */
strcpy( buf, "\033[?1002h" );