Console fix

Eric Pouech Eric.Pouech at wanadoo.fr
Mon Feb 12 16:08:37 CST 2001


when starting a new process, Wine tries to allocate the Windows 
standard IO streams for it

in case the process is created by an existing Windows process, 
the IO streams are inherited (except in some cases, but that's
not the point here)

however, when the process doesn't have a Windows parent (it's
the case for most of the emulated programs run thru wine, and
the Winelib programs launched from the command line), the 
current behavior was to dub the unix IO streams from the 
wineserver

this works fine, when a process is run from a tty. when the
wineserver is launched, it inherits (unix level) the FDs from
the tty, which will then be used as standard stream handles
for Windows console APIs

however, when two processes are started separately, in two
different TTYs, the second process outputs its Windows console
output in the first process TTY (the unix output goes to the
right TTY, of course)

this patch forces a windows process without parent to redirect
its windows standard IO streams to the startup TTY (or whatever
0, 1 and 2 are linked to)

(must use make_request after applying it)

A+
-- 
---------------
Eric Pouech (http://perso.wanadoo.fr/eric.pouech/)
"The future will be better tomorrow", Vice President Dan Quayle
-------------- next part --------------
Name: conproc
ChangeLog: fixed std console stream creation (inherit them from current tty)
GenDate: 2001/02/12 21:59:26 UTC
ModifiedFiles: include/server.h scheduler/process.c server/process.c
AddedFiles: 
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/include/server.h,v
retrieving revision 1.85
diff -u -u -r1.85 server.h
--- include/server.h	2001/01/26 20:45:42	1.85
+++ include/server.h	2001/02/12 19:01:03
@@ -183,6 +183,7 @@
     OUT handle_t     hstdout;      /* handle for stdout */
     OUT handle_t     hstderr;      /* handle for stderr */
     OUT int          cmd_show;     /* main window show mode */
+    OUT int          console_allocated;	/* did create a new console */
     OUT VARARG(filename,string);   /* file name of main exe */
 };
 
Index: scheduler/process.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/scheduler/process.c,v
retrieving revision 1.141
diff -u -u -r1.141 process.c
--- scheduler/process.c	2001/01/26 00:22:26	1.141
+++ scheduler/process.c	2001/02/12 17:41:34
@@ -219,7 +219,21 @@
     }
 }
 
+static void	inline PROCESS_SetFD(int fd, HANDLE hConStd)
+{
+    HANDLE h = FILE_DupUnixHandle( fd, GENERIC_READ | GENERIC_WRITE );
 
+    SERVER_START_REQ
+    {
+        struct set_console_fd_request *req = server_alloc_req( sizeof(*req), 0 );
+	req->handle = hConStd;
+	req->file_handle = h;
+	req->pid = 0;
+	server_call( REQ_SET_CONSOLE_FD );
+    }
+    SERVER_END_REQ;
+}
+
 /***********************************************************************
  *           process_init
  *
@@ -228,6 +242,7 @@
 static BOOL process_init( char *argv[] )
 {
     BOOL ret;
+    int console_allocated = 0;
 
     /* store the program name */
     argv0 = argv[0];
@@ -265,13 +280,22 @@
             current_startupinfo.hStdInput   = req->hstdin;
             current_startupinfo.hStdOutput  = req->hstdout;
             current_startupinfo.hStdError   = req->hstderr;
-            SetStdHandle( STD_INPUT_HANDLE,  current_startupinfo.hStdInput );
-            SetStdHandle( STD_OUTPUT_HANDLE, current_startupinfo.hStdOutput );
-            SetStdHandle( STD_ERROR_HANDLE,  current_startupinfo.hStdError );
+	    console_allocated               = req->console_allocated;
         }
     }
     SERVER_END_REQ;
     if (!ret) return FALSE;
+
+    /* set the Windows console IO streams from the Unix stream when needed */
+    if (console_allocated)
+    {
+        PROCESS_SetFD( 0, current_startupinfo.hStdInput );
+	PROCESS_SetFD( 1, current_startupinfo.hStdOutput );
+	PROCESS_SetFD( 2, current_startupinfo.hStdError );
+    }
+    SetStdHandle( STD_INPUT_HANDLE,  current_startupinfo.hStdInput );
+    SetStdHandle( STD_OUTPUT_HANDLE, current_startupinfo.hStdOutput );
+    SetStdHandle( STD_ERROR_HANDLE,  current_startupinfo.hStdError );
 
     /* Create the system and process heaps */
     if (!HEAP_CreateSystemHeap()) return FALSE;
Index: server/process.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/server/process.c,v
retrieving revision 1.65
diff -u -u -r1.65 process.c
--- server/process.c	2001/01/26 00:22:26	1.65
+++ server/process.c	2001/02/10 14:51:33
@@ -96,11 +96,14 @@
 
 /* set the console and stdio handles for a newly created process */
 static int set_process_console( struct process *process, struct process *parent,
-                                struct startup_info *info, struct init_process_request *req )
+                                struct startup_info *info, struct init_process_request *req,
+										  int *allocated)
 {
+	 *allocated = 0;
     if (process->create_flags & CREATE_NEW_CONSOLE)
     {
         if (!alloc_console( process )) return 0;
+		  *allocated = 1;
     }
     else if (parent && !(process->create_flags & DETACHED_PROCESS))
     {
@@ -240,7 +243,7 @@
     }
 
     /* set the process console */
-    if (!set_process_console( process, parent, info, req )) goto error;
+    if (!set_process_console( process, parent, info, req, &req->console_allocated )) goto error;
 
     if (parent)
     {


More information about the wine-patches mailing list