summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-06 20:35:30 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-06 20:35:30 +0000
commit04918f8156127d671ca207f14583e2e694476fde (patch)
tree9faa28fd2049c451d9bab5e3ad9cb5d396d78467 /ruby.c
parentea0ef6af8388ecdfdaa166242b5e3d82d906eb11 (diff)
merge revision(s) 33567,33573:
* ruby.c (fill_standard_fds): new function to open closed standard file descriptors. (ruby_sysinit): call fill_standard_fds. * ruby.c (fill_standard_fds): use fstat() instead of fcntl(F_GETFD) for MinGW. reported by Luis Lavena. [ruby-core:40526] [Bug #5516] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/ruby.c b/ruby.c
index f2c92fc426..3c97d01ddd 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1815,6 +1815,36 @@ ruby_process_options(int argc, char **argv)
return (void*)(struct RData*)iseq;
}
+static void
+fill_standard_fds(void)
+{
+ int f0, f1, f2, fds[2];
+ struct stat buf;
+ f0 = fstat(0, &buf) == -1 && errno == EBADF;
+ f1 = fstat(1, &buf) == -1 && errno == EBADF;
+ f2 = fstat(2, &buf) == -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 +1857,5 @@ ruby_sysinit(int *argc, char ***argv)
#if defined(USE_DLN_A_OUT)
dln_argv0 = origarg.argv[0];
#endif
+ fill_standard_fds();
}