Change 18377 by gsar@rake on 2002/12/31 04:02:12
change#17566 needs to be more defensive about win32_dup2()
itself calling SetStdHandle() (at least MSVCRT does this)
Affected files ...
... //depot/maint-5.6/perl/win32/win32.c#37 edit
Differences ...
==== //depot/maint-5.6/perl/win32/win32.c#37 (text) ====
Index: perl/win32/win32.c
--- perl/win32/win32.c#36~18329~ Tue Dec 17 18:28:47 2002
+++ perl/win32/win32.c Mon Dec 30 20:02:12 2002
@@ -2460,6 +2460,12 @@
if ((oldfd = win32_dup(stdfd)) == -1)
goto cleanup;
+ /* save the old std handle (this needs to happen before the
+ * dup2(), since that might call SetStdHandle() too) */
+ OP_REFCNT_LOCK;
+ lock_held = 1;
+ old_h = GetStdHandle(nhandle);
+
/* make stdfd go to child end of pipe (implicitly closes stdfd) */
/* stdfd will be inherited by the child */
if (win32_dup2(p[child], stdfd) == -1)
@@ -2468,10 +2474,7 @@
/* close the child end in parent */
win32_close(p[child]);
- /* save the old std handle, and set the std handle */
- OP_REFCNT_LOCK;
- lock_held = 1;
- old_h = GetStdHandle(nhandle);
+ /* set the new std handle (in case dup2() above didn't) */
SetStdHandle(nhandle, (HANDLE)_get_osfhandle(stdfd));
/* start the child */
@@ -2480,16 +2483,17 @@
if ((childpid = do_spawn_nowait((char*)command)) == -1)
goto cleanup;
- /* restore the old std handle */
+ /* revert stdfd to whatever it was before */
+ if (win32_dup2(oldfd, stdfd) == -1)
+ goto cleanup;
+
+ /* restore the old std handle (this needs to happen after the
+ * dup2(), since that might call SetStdHandle() too */
if (lock_held) {
SetStdHandle(nhandle, old_h);
OP_REFCNT_UNLOCK;
lock_held = 0;
}
-
- /* revert stdfd to whatever it was before */
- if (win32_dup2(oldfd, stdfd) == -1)
- goto cleanup;
/* close saved handle */
win32_close(oldfd);
End of Patch.