Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
win/process.c: stdio fd should default to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed May 28, 2012
1 parent 18e622d commit 7556590
Showing 1 changed file with 26 additions and 43 deletions.
69 changes: 26 additions & 43 deletions src/win/process.c
Expand Up @@ -640,26 +640,28 @@ static DWORD WINAPI spawn_failure(void* data) {
char* buf = NULL;
DWORD count, written;

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

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

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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7556590

Please sign in to comment.