summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-26 13:01:16 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-26 13:01:16 +0000
commitc86115e9961c85736d2672a015e3113780551db1 (patch)
tree8b6279a5c8263347b7ba22c97fb68d9d6b6228c4 /ext
parentcadee06b2a09c309b0fb944251a8105b449d7dd1 (diff)
* ext/pty/pty.c (pty_getpty): check dup failure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/pty/pty.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index 5db349872c..b4394c207c 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -511,7 +511,27 @@ pty_detach_process(struct pty_info *info)
return Qnil;
}
-/* ruby function: getpty */
+/*
+ * call-seq:
+ * PTY.spawn(command...) {|r, w, pid| ... } => nil
+ * PTY.spawn(command...) => r, w, pid
+ * PTY.getpty(command...) {|r, w, pid| ... } => nil
+ * PTY.getpty(command...) => r, w, pid
+ *
+ * spawns the specified command on a newly allocated pty.
+ *
+ * The command's controlling tty is set to the slave device of the pty.
+ * Also its standard input/output/error is redirected to the slave device.
+ *
+ * PTY.spawn returns two IO objects and PID.
+ * PID is the process ID of the command.
+ * The two IO objects are connected to the master device of the pty.
+ * The first IO object is opened as read mode and
+ * The second is opened as write mode.
+ *
+ * If a block is given, two IO objects and PID is yielded.
+ *
+ */
static VALUE
pty_getpty(int argc, VALUE *argv, VALUE self)
{
@@ -533,6 +553,8 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
wfptr->mode = rb_io_mode_flags("w") | FMODE_SYNC;
wfptr->fd = dup(info.fd);
+ if (wfptr->fd == -1)
+ rb_sys_fail("dup()");
wfptr->pathv = rfptr->pathv;
res = rb_ary_new2(3);