emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master de7de561e1e 1/2: Use SetHandleInformation to set NOINHERIT in UCR


From: Eli Zaretskii
Subject: master de7de561e1e 1/2: Use SetHandleInformation to set NOINHERIT in UCRT64
Date: Fri, 9 Aug 2024 07:01:00 -0400 (EDT)

branch: master
commit de7de561e1e3a973581b6993b3cc0074ff0bf91c
Author: Kien Nguyen <kien.n.quang@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    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
---
 src/w32.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

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)
   /* Initial preparation for subprocess support: replace our standard
      handles with non-inheritable versions. */
   {
+
+#ifdef _UCRT
+    /* For UCRT, the _fdopen will try to find free stream from
+       _IOB_ENTRIES (= 3), thus we can't reopen the standard handles
+       with it. Using SetHandleInformation to make the handle not
+       inheritable to child process is a better way. */
+    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);
+#else
     HANDLE parent;
     HANDLE stdin_save =  INVALID_HANDLE_VALUE;
     HANDLE stdout_save = INVALID_HANDLE_VALUE;
@@ -10534,6 +10544,7 @@ init_ntproc (int dumping)
     else
       _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
     _fdopen (2, "w");
+#endif
   }
 
   /* unfortunately, atexit depends on implementation of malloc */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]