From 75565907073055dd717fb6a6074518cafdd9355d Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 29 May 2012 00:53:04 +0200 Subject: [PATCH] win/process.c: stdio fd should default to ignore --- src/win/process.c | 65 +++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/src/win/process.c b/src/win/process.c index dd0101b0..e3d8a1fd 100644 --- a/src/win/process.c +++ b/src/win/process.c @@ -640,27 +640,29 @@ static DWORD WINAPI spawn_failure(void* data) { char* buf = NULL; DWORD count, written; - WriteFile(child_stderr, syscall, sizeof(syscall) - 1, &written, NULL); + if (child_stderr != INVALID_HANDLE_VALUE) { + WriteFile(child_stderr, syscall, sizeof(syscall) - 1, &written, NULL); - count = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - process->spawn_errno, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR) &buf, - 0, - NULL); + count = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + process->spawn_errno, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &buf, + 0, + NULL); - if (buf != NULL && count > 0) { - WriteFile(child_stderr, buf, count, &written, NULL); - LocalFree(buf); - } else { - WriteFile(child_stderr, unknown, sizeof(unknown) - 1, &written, NULL); + if (buf != NULL && count > 0) { + WriteFile(child_stderr, buf, count, &written, NULL); + LocalFree(buf); + } else { + WriteFile(child_stderr, unknown, sizeof(unknown) - 1, &written, NULL); + } + + FlushFileBuffers(child_stderr); } - FlushFileBuffers(child_stderr); - /* Post completed */ POST_COMPLETION_FOR_REQ(loop, &process->exit_req); @@ -674,7 +676,7 @@ static void close_child_stdio(uv_process_t* process) { for (i = 0; i < ARRAY_SIZE(process->child_stdio); i++) { handle = process->child_stdio[i]; - if (handle != NULL && handle != INVALID_HANDLE_VALUE) { + if (handle != INVALID_HANDLE_VALUE) { CloseHandle(handle); process->child_stdio[i] = INVALID_HANDLE_VALUE; } @@ -940,8 +942,10 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process, application_path = application; } - for (i = 0; i < options.stdio_count; i++) { - if (options.stdio[i].flags == UV_IGNORE) { + for (i = 0; i < options.stdio_count || i < 3; i++) { + if (i >= options.stdio_count || + options.stdio[i].flags == UV_IGNORE) { + child_stdio[i] = INVALID_HANDLE_VALUE; continue; } @@ -994,27 +998,6 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process, } } - if (child_stdio[0] == INVALID_HANDLE_VALUE) { - err = duplicate_std_handle(loop, STD_INPUT_HANDLE, &child_stdio[0]); - if (err) { - goto done; - } - } - - if (child_stdio[1] == INVALID_HANDLE_VALUE) { - err = duplicate_std_handle(loop, STD_OUTPUT_HANDLE, &child_stdio[1]); - if (err) { - goto done; - } - } - - if (child_stdio[2] == INVALID_HANDLE_VALUE) { - err = duplicate_std_handle(loop, STD_ERROR_HANDLE, &child_stdio[2]); - if (err) { - goto done; - } - } - startup.cb = sizeof(startup); startup.lpReserved = NULL; startup.lpDesktop = NULL;