From 87dbea7bbf97746de91388bd63180faddf0ed6f5 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sun, 22 May 2011 02:45:12 +0000 Subject: [PATCH] * ext/pty/pty.c: Improve documentaton. Patch by David Copeland. [Ruby 1.9 - Bug #4756] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++ ext/pty/pty.c | 101 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 77 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19a4fae7b7..7ca6a707aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun May 22 11:44:53 2011 Eric Hodel + + * ext/pty/pty.c: Improve documentaton. Patch by David Copeland. + [Ruby 1.9 - Bug #4756] + Sun May 22 11:26:39 2011 Eric Hodel * lib/timeout.rb: Improve documentation. Patch by David Copeland. diff --git a/ext/pty/pty.c b/ext/pty/pty.c index 0c9f37e040..6a3ab5bd6b 100644 --- a/ext/pty/pty.c +++ b/ext/pty/pty.c @@ -122,6 +122,9 @@ char MasterDevice[] = "/dev/pty%s", static VALUE eChildExited; +/* Returns the exit status of the child for which PTY#check + * raised this exception + */ static VALUE echild_status(VALUE self) { @@ -428,20 +431,28 @@ pty_close_pty(VALUE assoc) /* * call-seq: - * PTY.open => [master_io, slave_file] - * PTY.open {|master_io, slave_file| ... } => block value + * PTY.open => [master_io, slave_file] + * PTY.open {|master_io, slave_file| ... } => block value * * Allocates a pty (pseudo-terminal). * - * It returns an array which contains an IO object and a File object. - * The former is the master of the pty. - * The latter is the slave of the pty. + * In the non-block form, returns a two element array, [master_io, + * slave_file]. * - * If a block is given, it yields the array instead of return. - * The value of the block is returned. - * master_io and slave_file is closed when return if they are not closed. + * In the block form, yields two arguments master_io, slave_file + * and the value of the block is returned from +open+. * - * The path name of the terminal device can be gotten by slave_file.path. + * The IO and File are both closed after the block completes if they haven't + * been already closed. + * + * The arguments in both forms are: + * + * master_io:: the master of the pty, as an IO. + * slave_file:: the slave of the pty, as a File. The path to the + * terminal device is available via + * slave_file.path + * + * === Example * * PTY.open {|m, s| * p m #=> # @@ -465,7 +476,8 @@ pty_close_pty(VALUE assoc) * w.puts "144" * p m.gets #=> "144: 2 2 2 2 3 3\n" * w.close - * # The result of read operation when pty slave is closed is platform dependnet. + * # The result of read operation when pty slave is closed is platform + * # dependent. * ret = begin * m.gets # FreeBSD returns nil. * rescue Errno::EIO # GNU/Linux raises EIO. @@ -513,24 +525,34 @@ pty_detach_process(struct pty_info *info) /* * 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 + * PTY.spawn(command_line) { |r, w, pid| ... } + * PTY.spawn(command_line) => [r, w, pid] + * PTY.spawn(command, args, ...) { |r, w, pid| ... } + * PTY.spawn(command, args, ...) => [r, w, pid] + * PTY.getpty(command_line) { |r, w, pid| ... } + * PTY.getpty(command_line) => [r, w, pid] + * PTY.getpty(command, args, ...) { |r, w, pid| ... } + * PTY.getpty(command, args, ...) => [r, w, pid] * - * spawns the specified command on a newly allocated pty. + * 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. + * The command's controlling tty is set to the slave device of the pty + * and 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. + * command_line:: The full command line to run + * command:: The command to run, as a String. + * args:: Zero or more arguments, as Strings, representing + * the arguments to +command+ * - * If a block is given, two IO objects and PID is yielded. + * In the non-block form this returns an array of size three, + * [r, w, pid]. In the block form the block will be called with + * these as arguments, |r,w,pid|: * + * +r+:: An IO that can be read from that contains the command's + * standard output and standard error + * +w+:: An IO that can be written to that is the command's + * standard input + * +pid+:: The process identifier for the command. */ static VALUE pty_getpty(int argc, VALUE *argv, VALUE self) @@ -599,12 +621,19 @@ raise_from_check(pid_t pid, int status) /* * call-seq: - * PTY.check(pid[, raise=false]) => Process::Status or nil + * PTY.check(pid, raise = false) => Process::Status or nil + * PTY.check(pid, true) => nil or raises PTY::ChildExited * - * checks the status of the child process specified by _pid_, and - * returns +nil+ if the process is still alive and active. Otherwise, - * returns +Process::Status+ about the process if _raise_ is false, or - * +PTY::ChildExited+ exception is raised. + * Checks the status of the child process specified by +pid+. + * Returns +nil+ if the process is still alive. If the process + * is not alive, will return a Process::Status or raise + * a PTY::ChildExited (if +raise+ was true). + * + * +pid+:: The process id of the process to check + * +raise+:: If true and the process identified by +pid+ is no longer + * alive a PTY::ChildExited is raised. + * + * Returns nil or a Process::Status when +raise+ is false. */ static VALUE pty_check(int argc, VALUE *argv, VALUE self) @@ -619,11 +648,25 @@ pty_check(int argc, VALUE *argv, VALUE self) if (!RTEST(exc)) return rb_last_status_get(); raise_from_check(cpid, status); - return Qnil; /* not reached */ + return Qnil; } static VALUE cPTY; +/* + * Document-class: PTY::ChildExited + * + * Thrown when PTY#check is called for a pid that represents a process that + * has exited. + */ + +/* + * Document-class: PTY + * + * Creates and managed pseudo terminals (PTYs). See also + * http://en.wikipedia.org/wiki/Pseudo_terminal + */ + void Init_pty() {