kernel32: Reset stdio file descriptors when passed invalid handles.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
280d10b277
commit
171dab0696
|
@ -2029,6 +2029,27 @@ static BOOL terminate_main_thread(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* set_stdio_fd
|
||||||
|
*/
|
||||||
|
static void set_stdio_fd( int stdin_fd, int stdout_fd )
|
||||||
|
{
|
||||||
|
int fd = -1;
|
||||||
|
|
||||||
|
if (stdin_fd == -1 || stdout_fd == -1)
|
||||||
|
{
|
||||||
|
fd = open( "/dev/null", O_RDWR );
|
||||||
|
if (stdin_fd == -1) stdin_fd = fd;
|
||||||
|
if (stdout_fd == -1) stdout_fd = fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
dup2( stdin_fd, 0 );
|
||||||
|
dup2( stdout_fd, 1 );
|
||||||
|
if (fd != -1) close( fd );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* spawn_loader
|
* spawn_loader
|
||||||
*/
|
*/
|
||||||
|
@ -2060,21 +2081,10 @@ static pid_t spawn_loader( const RTL_USER_PROCESS_PARAMETERS *params, int socket
|
||||||
if (params->ConsoleFlags || params->ConsoleHandle == KERNEL32_CONSOLE_ALLOC ||
|
if (params->ConsoleFlags || params->ConsoleHandle == KERNEL32_CONSOLE_ALLOC ||
|
||||||
(params->hStdInput == INVALID_HANDLE_VALUE && params->hStdOutput == INVALID_HANDLE_VALUE))
|
(params->hStdInput == INVALID_HANDLE_VALUE && params->hStdOutput == INVALID_HANDLE_VALUE))
|
||||||
{
|
{
|
||||||
int fd = open( "/dev/null", O_RDWR );
|
|
||||||
setsid();
|
setsid();
|
||||||
/* close stdin and stdout */
|
set_stdio_fd( -1, -1 ); /* close stdin and stdout */
|
||||||
if (fd != -1)
|
|
||||||
{
|
|
||||||
dup2( fd, 0 );
|
|
||||||
dup2( fd, 1 );
|
|
||||||
close( fd );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (stdin_fd != -1) dup2( stdin_fd, 0 );
|
|
||||||
if (stdout_fd != -1) dup2( stdout_fd, 1 );
|
|
||||||
}
|
}
|
||||||
|
else set_stdio_fd( stdin_fd, stdout_fd );
|
||||||
|
|
||||||
if (stdin_fd != -1) close( stdin_fd );
|
if (stdin_fd != -1) close( stdin_fd );
|
||||||
if (stdout_fd != -1) close( stdout_fd );
|
if (stdout_fd != -1) close( stdout_fd );
|
||||||
|
|
Loading…
Reference in New Issue