ruby-changes:25336
From: usa <ko1@a...>
Date: Tue, 30 Oct 2012 19:33:19 +0900 (JST)
Subject: [ruby-changes:25336] usa:r37388 (trunk): * process.c (redirect_dup2): set standard handles when new fd is stdio,
usa 2012-10-30 19:32:56 +0900 (Tue, 30 Oct 2012) New Revision: 37388 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37388 Log: * 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. Modified files: trunk/ChangeLog trunk/io.c trunk/process.c Index: ChangeLog =================================================================== --- ChangeLog (revision 37387) +++ ChangeLog (revision 37388) @@ -1,3 +1,13 @@ +Tue Oct 30 19:27:48 2012 NAKAMURA Usaku <usa@r...> + + * 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. + Tue Oct 30 03:08:53 2012 Nobuyoshi Nakada <nobu@r...> * lib/rbconfig/obsolete.rb (Config): re-introduce warnings for a Index: io.c =================================================================== --- io.c (revision 37387) +++ io.c (revision 37388) @@ -244,6 +244,10 @@ } #else ret = dup2(oldfd, newfd); +# ifdef _WIN32 + 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)); +# endif #endif if (ret == -1) return -1; } Index: process.c =================================================================== --- process.c (revision 37387) +++ process.c (revision 37388) @@ -2438,16 +2438,28 @@ 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) { @@ -2467,8 +2479,6 @@ } #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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/