emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 0322457 2/2: Port redirect-debugging-output to MS-W


From: Paul Eggert
Subject: [Emacs-diffs] master 0322457 2/2: Port redirect-debugging-output to MS-Windows
Date: Mon, 04 Apr 2016 16:44:24 +0000

branch: master
commit 0322457e2bec0b9409a03887a8235dbe14e357f4
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Port redirect-debugging-output to MS-Windows
    
    Suggested by Eli Zaretskii in:
    http://lists.gnu.org/archive/html/emacs-devel/2016-04/msg00037.html
    * src/print.c [WINDOWSNT]: Include sys/socket.h.
    * src/w32.c (sys_dup2): Work around problem with MS-Windows _dup2.
---
 src/print.c |    4 ++++
 src/w32.c   |   24 ++++++++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/print.c b/src/print.c
index db2918f..83edbb6 100644
--- a/src/print.c
+++ b/src/print.c
@@ -38,6 +38,10 @@ along with GNU Emacs.  If not, see 
<http://www.gnu.org/licenses/>.  */
 #include <float.h>
 #include <ftoastr.h>
 
+#ifdef WINDOWSNT
+# include <sys/socket.h> /* for F_DUPFD_CLOEXEC */
+#endif
+
 struct terminal;
 
 /* Avoid actual stack overflow in print.  */
diff --git a/src/w32.c b/src/w32.c
index 3f4ac88..94aa7d8 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -8181,17 +8181,33 @@ sys_dup2 (int src, int dst)
       return -1;
     }
 
-  /* make sure we close the destination first if it's a pipe or socket */
-  if (src != dst && fd_info[dst].flags != 0)
+  /* MS _dup2 seems to have weird side effect when invoked with 2
+     identical arguments: an attempt to fclose the corresponding stdio
+     stream after that hangs (we do close standard streams in
+     init_ntproc).  Attempt to avoid that by not calling _dup2 that
+     way: if SRC is valid, we know that dup2 should be a no-op, so do
+     nothing and return DST.  */
+  if (src == dst)
+    {
+      if ((HANDLE)_get_osfhandle (src) == INVALID_HANDLE_VALUE)
+       {
+         errno = EBADF;
+         return -1;
+       }
+      return dst;
+    }
+
+  /* Make sure we close the destination first if it's a pipe or socket.  */
+  if (fd_info[dst].flags != 0)
     sys_close (dst);
 
   rc = _dup2 (src, dst);
   if (rc == 0)
     {
-      /* duplicate our internal info as well */
+      /* Duplicate our internal info as well.  */
       fd_info[dst] = fd_info[src];
     }
-  return rc;
+  return rc == 0 ? dst : rc;
 }
 
 int



reply via email to

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