mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/io/console/console.c (console_dev): take care of no-ctty
case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bcfc22b10e
commit
a7b0b52f09
3 changed files with 32 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Jun 13 23:28:50 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/io/console/console.c (console_dev): take care of no-ctty
|
||||||
|
case.
|
||||||
|
|
||||||
Mon Jun 13 23:06:12 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Mon Jun 13 23:06:12 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* thread_pthread.c: rewrite GVL completely.
|
* thread_pthread.c: rewrite GVL completely.
|
||||||
|
|
|
@ -557,27 +557,36 @@ console_dev(VALUE klass)
|
||||||
VALUE out;
|
VALUE out;
|
||||||
rb_io_t *ofptr;
|
rb_io_t *ofptr;
|
||||||
#endif
|
#endif
|
||||||
|
int fd, mode;
|
||||||
|
|
||||||
args[1] = INT2FIX(O_RDWR);
|
|
||||||
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
||||||
args[0] = rb_str_new2(CONSOLE_DEVICE_FOR_WRITING);
|
fd = open(CONSOLE_DEVICE_FOR_WRITING, O_WRONLY);
|
||||||
|
if (fd < 0) return Qnil;
|
||||||
|
args[1] = INT2FIX(O_WRONLY);
|
||||||
|
args[0] = INT2NUM(fd);
|
||||||
out = rb_class_new_instance(2, args, klass);
|
out = rb_class_new_instance(2, args, klass);
|
||||||
#endif
|
#endif
|
||||||
args[0] = rb_str_new2(CONSOLE_DEVICE_FOR_READING);
|
fd = open(CONSOLE_DEVICE_FOR_READING, O_RDWR);
|
||||||
con = rb_class_new_instance(2, args, klass);
|
if (fd < 0) {
|
||||||
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
||||||
|
rb_io_close(out);
|
||||||
|
#endif
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
args[1] = INT2FIX(O_RDWR);
|
||||||
|
args[0] = INT2NUM(fd);
|
||||||
|
con = rb_class_new_instance(2, args, klass);
|
||||||
GetOpenFile(con, fptr);
|
GetOpenFile(con, fptr);
|
||||||
|
fptr->pathv = rb_obj_freeze(rb_str_new2(CONSOLE_DEVICE));
|
||||||
|
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
||||||
GetOpenFile(out, ofptr);
|
GetOpenFile(out, ofptr);
|
||||||
# ifdef HAVE_RB_IO_GET_WRITE_IO
|
# ifdef HAVE_RB_IO_GET_WRITE_IO
|
||||||
# ifdef _WIN32
|
ofptr->pathv = fptr->pathv;
|
||||||
ofptr->pathv = fptr->pathv = rb_str_new2(CONSOLE_DEVICE);
|
|
||||||
# endif
|
|
||||||
fptr->tied_io_for_writing = out;
|
fptr->tied_io_for_writing = out;
|
||||||
# else
|
# else
|
||||||
fptr->f2 = ofptr->f;
|
fptr->f2 = ofptr->f;
|
||||||
ofptr->f = 0;
|
ofptr->f = 0;
|
||||||
# endif
|
# endif
|
||||||
fptr->mode |= FMODE_WRITABLE;
|
|
||||||
#endif
|
#endif
|
||||||
rb_const_set(klass, id_console, con);
|
rb_const_set(klass, id_console, con);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,3 +160,13 @@ class TestIO_Console < Test::Unit::TestCase
|
||||||
s.close if s
|
s.close if s
|
||||||
end
|
end
|
||||||
end if defined?(PTY) and defined?(IO::console)
|
end if defined?(PTY) and defined?(IO::console)
|
||||||
|
|
||||||
|
class TestIO_Console < Test::Unit::TestCase
|
||||||
|
require_relative '../../ruby/envutil'
|
||||||
|
|
||||||
|
def test_noctty
|
||||||
|
assert_in_out_err(["-rio/console"],
|
||||||
|
"Process.daemon(true, true); p IO.console",
|
||||||
|
["nil"])
|
||||||
|
end
|
||||||
|
end if defined?(Process.daemon) and defined?(IO::console)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue