ruby-changes:21518
From: akr <ko1@a...>
Date: Sun, 30 Oct 2011 18:47:06 +0900 (JST)
Subject: [ruby-changes:21518] akr:r33567 (trunk): * ruby.c (fill_standard_fds): new function to open closed standard
akr 2011-10-30 18:46:56 +0900 (Sun, 30 Oct 2011) New Revision: 33567 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33567 Log: * ruby.c (fill_standard_fds): new function to open closed standard file descriptors. (ruby_sysinit): call fill_standard_fds. Modified files: trunk/ChangeLog trunk/ruby.c Index: ChangeLog =================================================================== --- ChangeLog (revision 33566) +++ ChangeLog (revision 33567) @@ -1,3 +1,9 @@ +Sun Oct 30 18:45:50 2011 Tanaka Akira <akr@f...> + + * ruby.c (fill_standard_fds): new function to open closed standard + file descriptors. + (ruby_sysinit): call fill_standard_fds. + Sun Oct 30 10:50:36 2011 Nobuyoshi Nakada <nobu@r...> * tool/rbinstall.rb (install_recursive, bin-comm): split mere Index: ruby.c =================================================================== --- ruby.c (revision 33566) +++ ruby.c (revision 33567) @@ -1815,6 +1815,35 @@ return (void*)(struct RData*)iseq; } +static void +fill_standard_fds(void) +{ + int f0, f1, f2, fds[2]; + f0 = fcntl(0, F_GETFD) == -1 && errno == EBADF; + f1 = fcntl(1, F_GETFD) == -1 && errno == EBADF; + f2 = fcntl(2, F_GETFD) == -1 && errno == EBADF; + if (f0) { + if (pipe(fds) == 0) { + close(fds[1]); + if (fds[0] != 0) { + dup2(fds[0], 0); + close(fds[0]); + } + } + } + if (f1 || f2) { + if (pipe(fds) == 0) { + close(fds[0]); + if (f1 && fds[1] != 1) + dup2(fds[1], 1); + if (f2 && fds[1] != 2) + dup2(fds[1], 2); + if (fds[1] != 1 && fds[1] != 2) + close(fds[1]); + } + } +} + void ruby_sysinit(int *argc, char ***argv) { @@ -1827,4 +1856,5 @@ #if defined(USE_DLN_A_OUT) dln_argv0 = origarg.argv[0]; #endif + fill_standard_fds(); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/