Visual studio 6 build fix.
Rein Klazes
wijn at wanadoo.nl
Tue Dec 14 09:21:41 CST 2004
On Sun, 12 Dec 2004 14:02:54 +0100, you wrote:
> > Is this one acceptable?
> >
> > If there is still a problem, then I need more hints to what is needed.
> the only part which is questionnable is as follows:
> - what happens (in your case) if the child (after being run through all the
> init) calls FreeConsole and then AllocConsole?
> - I don't know the answer. The patch will let the new standard handles be still
> the ones the child as inherited, while it could be the ones allocated by
> AllocConsole.
> I don't know the answer for sure (my wild guess would be the second), but that
> requires testing (and a proper test case for winetest wouldn't hurt of course).
> If I'm right, then you should keep AllocConsole as it is and in
> dlls/kernel/kernel_main.c set the default handles to what's inherited after
> calling AllocConsole
Eric,
Testing on Win2K:
If I do a FreeConsole() & AllocConsole() in a child that has obtained
stdio handles from the StartupInfo struct, I get exactly the same
handles. Even the CREATE_NEW_CONSOLE flag is irrelevant. In contrast, if
the handles are just inherited (no STARTF_USESTDHANDLES flag), I get new
handles directed to the new console.
So, with luck, I think my approach seems the correct one.
Resubmitting, with minor cleanups.
Changelog:
server : process.c
dlls/kernel : console.c
A starting process must obey the STARTF_USESTDHANDLES flag and
use the standard io handles from the StartupInfo structure, even
it is starting a new console.
Rein.
-------------- next part --------------
--- wine/server/process.c 2004-06-15 07:41:59.000000000 +0200
+++ mywine/server/process.c 2004-12-14 15:09:32.000000000 +0100
@@ -207,12 +207,7 @@ static void set_process_startup_state( s
static int set_process_console( struct process *process, struct thread *parent_thread,
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))
+ if (info && !(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
@@ -222,7 +217,7 @@ static int set_process_console( struct p
}
if (info)
{
- if (!info->inherit_all)
+ if (!info->inherit_all && !(process->create_flags & CREATE_NEW_CONSOLE))
{
reply->hstdin = duplicate_handle( parent_thread->process, info->hstdin, process,
0, TRUE, DUPLICATE_SAME_ACCESS );
--- wine/dlls/kernel/console.c 2004-09-15 09:51:46.000000000 +0200
+++ mywine/dlls/kernel/console.c 2004-12-14 15:30:54.000000000 +0100
@@ -1142,22 +1142,29 @@ BOOL WINAPI AllocConsole(void)
if (!start_console_renderer(&siConsole))
goto the_end;
- /* all std I/O handles are inheritable by default */
- sa.nLength = sizeof(sa);
- sa.lpSecurityDescriptor = NULL;
- sa.bInheritHandle = TRUE;
-
- handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
- 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 );
- if (handle_out == INVALID_HANDLE_VALUE) goto the_end;
-
- if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(), &handle_err,
- 0, TRUE, DUPLICATE_SAME_ACCESS))
- goto the_end;
+ if( !(siCurrent.dwFlags & STARTF_USESTDHANDLES) ) {
+ /* all std I/O handles are inheritable by default */
+ sa.nLength = sizeof(sa);
+ sa.lpSecurityDescriptor = NULL;
+ sa.bInheritHandle = TRUE;
+
+ handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
+ 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 );
+ if (handle_out == INVALID_HANDLE_VALUE) goto the_end;
+
+ if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(),
+ &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 */
SetStdHandle(STD_INPUT_HANDLE, handle_in);
More information about the wine-devel
mailing list