* 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
This commit is contained in:
akr 2011-10-30 09:46:56 +00:00
Родитель d67ac15c86
Коммит 7c43d8523c
2 изменённых файлов: 36 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Sun Oct 30 18:45:50 2011 Tanaka Akira <akr@fsij.org>
* 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@ruby-lang.org>
* tool/rbinstall.rb (install_recursive, bin-comm): split mere

30
ruby.c
Просмотреть файл

@ -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();
}