aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKien Nguyen2024-08-07 10:39:38 -0700
committerEli Zaretskii2024-08-09 13:54:27 +0300
commitde7de561e1e3a973581b6993b3cc0074ff0bf91c (patch)
tree682974649ec3bec029f3cfca780add93d3191804 /src
parent9f03300c5c626bf6f8f839be4943cc20db89c24d (diff)
downloademacs-de7de561e1e3a973581b6993b3cc0074ff0bf91c.tar.gz
emacs-de7de561e1e3a973581b6993b3cc0074ff0bf91c.zip
Use SetHandleInformation to set NOINHERIT in UCRT64
* src/w32.c (init_ntproc) [_UCRT]: Use SetHandleInformation to prevent standard handles from being inherited, instead of relying on MSVCRT-only behavior. For the details of the problem, see https://lists.gnu.org/archive/html/emacs-devel/2024-07/msg01129.html. Copyright-paperwork-exempt: yes
Diffstat (limited to 'src')
-rw-r--r--src/w32.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/w32.c b/src/w32.c
index 31ffa301c2f..0c1291f1094 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -10480,6 +10480,16 @@ init_ntproc (int dumping)
10480 /* Initial preparation for subprocess support: replace our standard 10480 /* Initial preparation for subprocess support: replace our standard
10481 handles with non-inheritable versions. */ 10481 handles with non-inheritable versions. */
10482 { 10482 {
10483
10484#ifdef _UCRT
10485 /* For UCRT, the _fdopen will try to find free stream from
10486 _IOB_ENTRIES (= 3), thus we can't reopen the standard handles
10487 with it. Using SetHandleInformation to make the handle not
10488 inheritable to child process is a better way. */
10489 SetHandleInformation (GetStdHandle(STD_INPUT_HANDLE), HANDLE_FLAG_INHERIT, 0);
10490 SetHandleInformation (GetStdHandle(STD_OUTPUT_HANDLE), HANDLE_FLAG_INHERIT, 0);
10491 SetHandleInformation (GetStdHandle(STD_ERROR_HANDLE), HANDLE_FLAG_INHERIT, 0);
10492#else
10483 HANDLE parent; 10493 HANDLE parent;
10484 HANDLE stdin_save = INVALID_HANDLE_VALUE; 10494 HANDLE stdin_save = INVALID_HANDLE_VALUE;
10485 HANDLE stdout_save = INVALID_HANDLE_VALUE; 10495 HANDLE stdout_save = INVALID_HANDLE_VALUE;
@@ -10534,6 +10544,7 @@ init_ntproc (int dumping)
10534 else 10544 else
10535 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY); 10545 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
10536 _fdopen (2, "w"); 10546 _fdopen (2, "w");
10547#endif
10537 } 10548 }
10538 10549
10539 /* unfortunately, atexit depends on implementation of malloc */ 10550 /* unfortunately, atexit depends on implementation of malloc */