diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-30 09:46:56 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-30 09:46:56 +0000 |
commit | 7c43d8523cadf8cd0483581fb8a50138b7fc4d9f (patch) | |
tree | e063fed0b2f2ecdc6163846a9294d828c187a473 /ruby.c | |
parent | d67ac15c86e14eec076acfc03a2224714a642ea7 (diff) | |
download | ruby-7c43d8523cadf8cd0483581fb8a50138b7fc4d9f.tar.gz |
* ruby.c (fill_standard_fds): new function to open closed standard
file descriptors.
(ruby_sysinit): call fill_standard_fds.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33567 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -1815,6 +1815,35 @@ ruby_process_options(int argc, char **argv) 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 @@ ruby_sysinit(int *argc, char ***argv) #if defined(USE_DLN_A_OUT) dln_argv0 = origarg.argv[0]; #endif + fill_standard_fds(); } |