Skip to content
This repository
Browse code

win/process.c: stdio fd should default to ignore

  • Loading branch information...
commit 75565907073055dd717fb6a6074518cafdd9355d 1 parent 18e622d
Bert Belder piscisaureus authored

Showing 1 changed file with 26 additions and 43 deletions. Show diff stats Hide diff stats

  1. +26 43 src/win/process.c
69 src/win/process.c
@@ -640,26 +640,28 @@ static DWORD WINAPI spawn_failure(void* data) {
640 640 char* buf = NULL;
641 641 DWORD count, written;
642 642
643   - WriteFile(child_stderr, syscall, sizeof(syscall) - 1, &written, NULL);
644   -
645   - count = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
646   - FORMAT_MESSAGE_FROM_SYSTEM |
647   - FORMAT_MESSAGE_IGNORE_INSERTS,
648   - NULL,
649   - process->spawn_errno,
650   - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
651   - (LPSTR) &buf,
652   - 0,
653   - NULL);
654   -
655   - if (buf != NULL && count > 0) {
656   - WriteFile(child_stderr, buf, count, &written, NULL);
657   - LocalFree(buf);
658   - } else {
659   - WriteFile(child_stderr, unknown, sizeof(unknown) - 1, &written, NULL);
660   - }
  643 + if (child_stderr != INVALID_HANDLE_VALUE) {
  644 + WriteFile(child_stderr, syscall, sizeof(syscall) - 1, &written, NULL);
  645 +
  646 + count = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  647 + FORMAT_MESSAGE_FROM_SYSTEM |
  648 + FORMAT_MESSAGE_IGNORE_INSERTS,
  649 + NULL,
  650 + process->spawn_errno,
  651 + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  652 + (LPSTR) &buf,
  653 + 0,
  654 + NULL);
  655 +
  656 + if (buf != NULL && count > 0) {
  657 + WriteFile(child_stderr, buf, count, &written, NULL);
  658 + LocalFree(buf);
  659 + } else {
  660 + WriteFile(child_stderr, unknown, sizeof(unknown) - 1, &written, NULL);
  661 + }
661 662
662   - FlushFileBuffers(child_stderr);
  663 + FlushFileBuffers(child_stderr);
  664 + }
663 665
664 666 /* Post completed */
665 667 POST_COMPLETION_FOR_REQ(loop, &process->exit_req);
@@ -674,7 +676,7 @@ static void close_child_stdio(uv_process_t* process) {
674 676
675 677 for (i = 0; i < ARRAY_SIZE(process->child_stdio); i++) {
676 678 handle = process->child_stdio[i];
677   - if (handle != NULL && handle != INVALID_HANDLE_VALUE) {
  679 + if (handle != INVALID_HANDLE_VALUE) {
678 680 CloseHandle(handle);
679 681 process->child_stdio[i] = INVALID_HANDLE_VALUE;
680 682 }
@@ -940,8 +942,10 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
940 942 application_path = application;
941 943 }
942 944
943   - for (i = 0; i < options.stdio_count; i++) {
944   - if (options.stdio[i].flags == UV_IGNORE) {
  945 + for (i = 0; i < options.stdio_count || i < 3; i++) {
  946 + if (i >= options.stdio_count ||
  947 + options.stdio[i].flags == UV_IGNORE) {
  948 + child_stdio[i] = INVALID_HANDLE_VALUE;
945 949 continue;
946 950 }
947 951
@@ -994,27 +998,6 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
994 998 }
995 999 }
996 1000
997   - if (child_stdio[0] == INVALID_HANDLE_VALUE) {
998   - err = duplicate_std_handle(loop, STD_INPUT_HANDLE, &child_stdio[0]);
999   - if (err) {
1000   - goto done;
1001   - }
1002   - }
1003   -
1004   - if (child_stdio[1] == INVALID_HANDLE_VALUE) {
1005   - err = duplicate_std_handle(loop, STD_OUTPUT_HANDLE, &child_stdio[1]);
1006   - if (err) {
1007   - goto done;
1008   - }
1009   - }
1010   -
1011   - if (child_stdio[2] == INVALID_HANDLE_VALUE) {
1012   - err = duplicate_std_handle(loop, STD_ERROR_HANDLE, &child_stdio[2]);
1013   - if (err) {
1014   - goto done;
1015   - }
1016   - }
1017   -
1018 1001 startup.cb = sizeof(startup);
1019 1002 startup.lpReserved = NULL;
1020 1003 startup.lpDesktop = NULL;

0 comments on commit 7556590

Please sign in to comment.
Something went wrong with that request. Please try again.