summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-22 05:33:46 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-22 05:33:46 +0000
commit8f83a5eea195801812e2fdb9d41e3d75f4bc8b58 (patch)
treef093a2967f4b38f7c0edfe6ef28d922e4aa5ee5d /process.c
parente119e192d7ed7a87c9d9d44620c09f089e434154 (diff)
merge revision(s) 37388: [Backport #9232]
* process.c (redirect_dup2): set standard handles when new fd is stdio, because if there is no allocated console at the moment Windows does not automatically associate it for child process's standard handle. this is adhoc workaround. reported by Martin Thiede at [ruby-core:48542] [Bug #7239]. * io.c (rb_cloexec_dup2): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/process.c b/process.c
index 99cfc69469..679d21dcf4 100644
--- a/process.c
+++ b/process.c
@@ -1949,16 +1949,28 @@ redirect_dup(int oldfd)
ttyprintf("dup(%d) => %d\n", oldfd, ret);
return ret;
}
+#else
+#define redirect_dup(oldfd) dup(oldfd)
+#endif
+#if defined(DEBUG_REDIRECT) || defined(_WIN32)
static int
redirect_dup2(int oldfd, int newfd)
{
int ret;
ret = dup2(oldfd, newfd);
+ if (newfd >= 0 && newfd <= 2)
+ SetStdHandle(newfd == 0 ? STD_INPUT_HANDLE : newfd == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE, (HANDLE)rb_w32_get_osfhandle(newfd));
+#if defined(DEBUG_REDIRECT)
ttyprintf("dup2(%d, %d)\n", oldfd, newfd);
+#endif
return ret;
}
+#else
+#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
+#endif
+#if defined(DEBUG_REDIRECT)
static int
redirect_close(int fd)
{
@@ -1978,8 +1990,6 @@ redirect_open(const char *pathname, int flags, mode_t perm)
}
#else
-#define redirect_dup(oldfd) dup(oldfd)
-#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
#define redirect_close(fd) close(fd)
#define redirect_open(pathname, flags, perm) open((pathname), (flags), (perm))
#endif