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

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-08-17 15:08:36 +02:00 committed by Alexandre Julliard
parent ca30fa5cb4
commit 30596feb03
4 changed files with 16 additions and 26 deletions

View File

@ -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)
{

View File

@ -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 );
}

View File

@ -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 );
}

View File

@ -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 );