Jacek Caban : server: Use passed console handle to inherit console for created process.

Alexandre Julliard julliard at winehq.org
Tue Aug 18 16:34:24 CDT 2020


Module: wine
Branch: master
Commit: 30596feb03098b392bd5078a1a2d390567681b3c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=30596feb03098b392bd5078a1a2d390567681b3c

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Aug 17 15:08:36 2020 +0200

server: Use passed console handle to inherit console for created process.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernelbase/process.c |  1 +
 server/console.c          | 37 +++++++++++++------------------------
 server/process.c          |  2 +-
 server/process.h          |  2 +-
 4 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/dlls/kernelbase/process.c b/dlls/kernelbase/process.c
index 58fba52415..936eed4d18 100644
--- a/dlls/kernelbase/process.c
+++ b/dlls/kernelbase/process.c
@@ -193,6 +193,7 @@ static RTL_USER_PROCESS_PARAMETERS *create_process_params( const WCHAR *filename
 
     if (flags & CREATE_NEW_PROCESS_GROUP) params->ConsoleFlags = 1;
     if (flags & CREATE_NEW_CONSOLE) params->ConsoleHandle = (HANDLE)1; /* KERNEL32_CONSOLE_ALLOC */
+    else if (!(flags & DETACHED_PROCESS)) params->ConsoleHandle = NtCurrentTeb()->Peb->ProcessParameters->ConsoleHandle;
 
     if (startup->dwFlags & STARTF_USESTDHANDLES)
     {
diff --git a/server/console.c b/server/console.c
index 54b7a74382..4509905c2c 100644
--- a/server/console.c
+++ b/server/console.c
@@ -620,40 +620,29 @@ int free_console( struct process *process )
  *	2/ parent is a renderer which launches process, and process should attach to the console
  *	   rendered by parent
  */
-obj_handle_t inherit_console( struct thread *parent_thread, struct process *parent, struct process *process,
+obj_handle_t inherit_console( struct thread *parent_thread, obj_handle_t handle, struct process *process,
                               obj_handle_t hconin )
 {
-    int done = 0;
+    struct console_input *console = NULL;
+
+    if (handle && !(console = (struct console_input *)get_handle_obj( current->process, handle, 0,
+                                                                      &console_input_ops )))
+        return 0;
 
     /* if parent is a renderer, then attach current process to its console
      * a bit hacky....
      */
-    if (hconin && parent_thread)
+    if (!console && hconin && parent_thread)
     {
-        struct console_input *console;
-
         /* FIXME: should we check some access rights ? */
-        if ((console = (struct console_input *)get_handle_obj( parent, hconin,
-                                                               0, &console_input_ops )))
-        {
-            if (console->renderer == parent_thread)
-            {
-                process->console = (struct console_input *)grab_object( console );
-                process->console->num_proc++;
-                done = 1;
-            }
-            release_object( console );
-        }
-        else clear_error();  /* ignore error */
-    }
-    /* otherwise, if parent has a console, attach child to this console */
-    if (!done && parent->console)
-    {
-        process->console = (struct console_input *)grab_object( parent->console );
-        process->console->num_proc++;
+        if (!(console = (struct console_input *)get_handle_obj( parent_thread->process, hconin,
+                                                                0, &console_input_ops )))
+            clear_error();  /* ignore error */
     }
+    if (!console) return 0;
 
-    if (!process->console) return 0;
+    process->console = console;
+    console->num_proc++;
     return alloc_handle( process, process->console,
                          SYNCHRONIZE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, 0 );
 }
diff --git a/server/process.c b/server/process.c
index 61ba1549e9..c1bdb591f6 100644
--- a/server/process.c
+++ b/server/process.c
@@ -1224,7 +1224,7 @@ DECL_HANDLER(new_process)
          * like if hConOut and hConIn are console handles, then they should be on the same
          * physical console
          */
-        info->data->console = inherit_console( parent_thread, parent,
+        info->data->console = inherit_console( parent_thread, info->data->console,
                                                process, req->inherit_all ? info->data->hstdin : 0 );
     }
 
diff --git a/server/process.h b/server/process.h
index 3944a67d57..0fdf070b78 100644
--- a/server/process.h
+++ b/server/process.h
@@ -131,7 +131,7 @@ extern void detach_debugged_processes( struct thread *debugger );
 extern void enum_processes( int (*cb)(struct process*, void*), void *user);
 
 /* console functions */
-extern obj_handle_t inherit_console( struct thread *parent_thread, struct process *parent,
+extern obj_handle_t inherit_console( struct thread *parent_thread, obj_handle_t handle,
                                      struct process *process, obj_handle_t hconin );
 extern int free_console( struct process *process );
 extern struct thread *console_get_renderer( struct console_input *console );




More information about the wine-cvs mailing list