Commit 5dc91e6c authored by Rein Klazes's avatar Rein Klazes Committed by Alexandre Julliard

A starting process must obey the STARTF_USESTDHANDLES flag and use the

standard io handles from the StartupInfo structure, even if it is starting a new console.
parent da10a46c
...@@ -1142,22 +1142,29 @@ BOOL WINAPI AllocConsole(void) ...@@ -1142,22 +1142,29 @@ BOOL WINAPI AllocConsole(void)
if (!start_console_renderer(&siConsole)) if (!start_console_renderer(&siConsole))
goto the_end; goto the_end;
/* all std I/O handles are inheritable by default */ if( !(siCurrent.dwFlags & STARTF_USESTDHANDLES) ) {
sa.nLength = sizeof(sa); /* all std I/O handles are inheritable by default */
sa.lpSecurityDescriptor = NULL; sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
0, &sa, OPEN_EXISTING, 0, 0 ); handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
if (handle_in == INVALID_HANDLE_VALUE) goto the_end; 0, &sa, OPEN_EXISTING, 0, 0 );
if (handle_in == INVALID_HANDLE_VALUE) goto the_end;
handle_out = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE,
0, &sa, OPEN_EXISTING, 0, 0 ); handle_out = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE,
if (handle_out == INVALID_HANDLE_VALUE) goto the_end; 0, &sa, OPEN_EXISTING, 0, 0 );
if (handle_out == INVALID_HANDLE_VALUE) goto the_end;
if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(), &handle_err,
0, TRUE, DUPLICATE_SAME_ACCESS)) if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(),
goto the_end; &handle_err, 0, TRUE, DUPLICATE_SAME_ACCESS))
goto the_end;
} else {
/* STARTF_USESTDHANDLES flag: use handles from StartupInfo */
handle_in = siCurrent.hStdInput;
handle_out = siCurrent.hStdOutput;
handle_err = siCurrent.hStdError;
}
/* NT resets the STD_*_HANDLEs on console alloc */ /* NT resets the STD_*_HANDLEs on console alloc */
SetStdHandle(STD_INPUT_HANDLE, handle_in); SetStdHandle(STD_INPUT_HANDLE, handle_in);
......
...@@ -207,22 +207,17 @@ static void set_process_startup_state( struct process *process, enum startup_sta ...@@ -207,22 +207,17 @@ static void set_process_startup_state( struct process *process, enum startup_sta
static int set_process_console( struct process *process, struct thread *parent_thread, static int set_process_console( struct process *process, struct thread *parent_thread,
struct startup_info *info, struct init_process_reply *reply ) struct startup_info *info, struct init_process_reply *reply )
{ {
if (process->create_flags & CREATE_NEW_CONSOLE)
{
/* let the process init do the allocation */
return 1;
}
else if (info && !(process->create_flags & DETACHED_PROCESS))
{
/* FIXME: some better error checking should be done...
* like if hConOut and hConIn are console handles, then they should be on the same
* physical console
*/
inherit_console( parent_thread, process, info->inherit_all ? info->hstdin : 0 );
}
if (info) if (info)
{ {
if (!info->inherit_all) if (!(process->create_flags & (DETACHED_PROCESS | CREATE_NEW_CONSOLE)))
{
/* FIXME: some better error checking should be done...
* like if hConOut and hConIn are console handles, then they should be on the same
* physical console
*/
inherit_console( parent_thread, process, info->inherit_all ? info->hstdin : 0 );
}
if (!info->inherit_all && !(process->create_flags & CREATE_NEW_CONSOLE))
{ {
reply->hstdin = duplicate_handle( parent_thread->process, info->hstdin, process, reply->hstdin = duplicate_handle( parent_thread->process, info->hstdin, process,
0, TRUE, DUPLICATE_SAME_ACCESS ); 0, TRUE, DUPLICATE_SAME_ACCESS );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment