Kien Nguyen
3 months ago
5 changed files with 115 additions and 59 deletions
@ -0,0 +1,80 @@ |
|||
From 65fb0e39e3e2b355735f0f94ea2c46f9665c3e2b Mon Sep 17 00:00:00 2001 |
|||
From: Kien Nguyen <kien.n.quang@gmail.com> |
|||
Date: Sun, 4 Aug 2024 04:29:35 -0700 |
|||
Subject: [PATCH] init_winntproc: Use SetHandleInformation to set NOINHERIT |
|||
|
|||
---
|
|||
src/w32.c | 57 +++------------------------------------------------- |
|||
1 file changed, 3 insertions(+), 54 deletions(-) |
|||
|
|||
diff --git a/src/w32.c b/src/w32.c
|
|||
index 31ffa301c2f..10d01ebb502 100644
|
|||
--- a/src/w32.c
|
|||
+++ b/src/w32.c
|
|||
@@ -10480,60 +10480,9 @@ init_ntproc (int dumping)
|
|||
/* Initial preparation for subprocess support: replace our standard |
|||
handles with non-inheritable versions. */ |
|||
{ |
|||
- HANDLE parent;
|
|||
- HANDLE stdin_save = INVALID_HANDLE_VALUE;
|
|||
- HANDLE stdout_save = INVALID_HANDLE_VALUE;
|
|||
- HANDLE stderr_save = INVALID_HANDLE_VALUE;
|
|||
-
|
|||
- parent = GetCurrentProcess ();
|
|||
-
|
|||
- /* ignore errors when duplicating and closing; typically the
|
|||
- handles will be invalid when running as a gui program. */
|
|||
- DuplicateHandle (parent,
|
|||
- GetStdHandle (STD_INPUT_HANDLE),
|
|||
- parent,
|
|||
- &stdin_save,
|
|||
- 0,
|
|||
- FALSE,
|
|||
- DUPLICATE_SAME_ACCESS);
|
|||
-
|
|||
- DuplicateHandle (parent,
|
|||
- GetStdHandle (STD_OUTPUT_HANDLE),
|
|||
- parent,
|
|||
- &stdout_save,
|
|||
- 0,
|
|||
- FALSE,
|
|||
- DUPLICATE_SAME_ACCESS);
|
|||
-
|
|||
- DuplicateHandle (parent,
|
|||
- GetStdHandle (STD_ERROR_HANDLE),
|
|||
- parent,
|
|||
- &stderr_save,
|
|||
- 0,
|
|||
- FALSE,
|
|||
- DUPLICATE_SAME_ACCESS);
|
|||
-
|
|||
- fclose (stdin);
|
|||
- fclose (stdout);
|
|||
- fclose (stderr);
|
|||
-
|
|||
- if (stdin_save != INVALID_HANDLE_VALUE)
|
|||
- _open_osfhandle ((intptr_t) stdin_save, O_TEXT);
|
|||
- else
|
|||
- _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY);
|
|||
- _fdopen (0, "r");
|
|||
-
|
|||
- if (stdout_save != INVALID_HANDLE_VALUE)
|
|||
- _open_osfhandle ((intptr_t) stdout_save, O_TEXT);
|
|||
- else
|
|||
- _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
|
|||
- _fdopen (1, "w");
|
|||
-
|
|||
- if (stderr_save != INVALID_HANDLE_VALUE)
|
|||
- _open_osfhandle ((intptr_t) stderr_save, O_TEXT);
|
|||
- else
|
|||
- _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
|
|||
- _fdopen (2, "w");
|
|||
+ SetHandleInformation(GetStdHandle(STD_INPUT_HANDLE), HANDLE_FLAG_INHERIT, 0);
|
|||
+ SetHandleInformation(GetStdHandle(STD_OUTPUT_HANDLE), HANDLE_FLAG_INHERIT, 0);
|
|||
+ SetHandleInformation(GetStdHandle(STD_ERROR_HANDLE), HANDLE_FLAG_INHERIT, 0);
|
|||
} |
|||
|
|||
/* unfortunately, atexit depends on implementation of malloc */ |
|||
--
|
|||
2.46.0.windows.1 |
|||
|
@ -1,32 +0,0 @@ |
|||
From 2e73677cbfe5236c9604b32ea7bfaf320f68c055 Mon Sep 17 00:00:00 2001 |
|||
From: Kien Nguyen <kien.n.quang@gmail.com> |
|||
Date: Sun, 4 Aug 2024 04:29:35 -0700 |
|||
Subject: [PATCH] init_winntproc: no need to reset to uninherited std handles |
|||
|
|||
---
|
|||
src/w32.c | 2 ++ |
|||
1 file changed, 2 insertions(+) |
|||
|
|||
diff --git a/src/w32.c b/src/w32.c
|
|||
index 31ffa301c2f..d854046af0d 100644
|
|||
--- a/src/w32.c
|
|||
+++ b/src/w32.c
|
|||
@@ -10477,6 +10477,7 @@ init_ntproc (int dumping)
|
|||
if (getenv ("PRELOAD_WINSOCK") != NULL) |
|||
init_winsock (TRUE); |
|||
|
|||
+#ifndef _UCRT /* The handles should be non-inheritable already */
|
|||
/* Initial preparation for subprocess support: replace our standard |
|||
handles with non-inheritable versions. */ |
|||
{ |
|||
@@ -10535,6 +10536,7 @@ init_ntproc (int dumping)
|
|||
_open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY); |
|||
_fdopen (2, "w"); |
|||
} |
|||
+#endif
|
|||
|
|||
/* unfortunately, atexit depends on implementation of malloc */ |
|||
/* atexit (term_ntproc); */ |
|||
--
|
|||
2.46.0.windows.1 |
|||
|
Loading…
Reference in new issue