mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
883fb2bbfc
commit
87dbea7bbf
2 changed files with 77 additions and 29 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun May 22 11:44:53 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* ext/pty/pty.c: Improve documentaton. Patch by David Copeland.
|
||||||
|
[Ruby 1.9 - Bug #4756]
|
||||||
|
|
||||||
Sun May 22 11:26:39 2011 Eric Hodel <drbrain@segment7.net>
|
Sun May 22 11:26:39 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* lib/timeout.rb: Improve documentation. Patch by David Copeland.
|
* lib/timeout.rb: Improve documentation. Patch by David Copeland.
|
||||||
|
|
|
@ -122,6 +122,9 @@ char MasterDevice[] = "/dev/pty%s",
|
||||||
|
|
||||||
static VALUE eChildExited;
|
static VALUE eChildExited;
|
||||||
|
|
||||||
|
/* Returns the exit status of the child for which PTY#check
|
||||||
|
* raised this exception
|
||||||
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
echild_status(VALUE self)
|
echild_status(VALUE self)
|
||||||
{
|
{
|
||||||
|
@ -433,15 +436,23 @@ pty_close_pty(VALUE assoc)
|
||||||
*
|
*
|
||||||
* Allocates a pty (pseudo-terminal).
|
* Allocates a pty (pseudo-terminal).
|
||||||
*
|
*
|
||||||
* It returns an array which contains an IO object and a File object.
|
* In the non-block form, returns a two element array, <tt>[master_io,
|
||||||
* The former is the master of the pty.
|
* slave_file]</tt>.
|
||||||
* The latter is the slave of the pty.
|
|
||||||
*
|
*
|
||||||
* If a block is given, it yields the array instead of return.
|
* In the block form, yields two arguments <tt>master_io, slave_file</tt>
|
||||||
* The value of the block is returned.
|
* and the value of the block is returned from +open+.
|
||||||
* master_io and slave_file is closed when return if they are not closed.
|
|
||||||
*
|
*
|
||||||
* 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:
|
||||||
|
*
|
||||||
|
* <tt>master_io</tt>:: the master of the pty, as an IO.
|
||||||
|
* <tt>slave_file</tt>:: the slave of the pty, as a File. The path to the
|
||||||
|
* terminal device is available via
|
||||||
|
* <tt>slave_file.path</tt>
|
||||||
|
*
|
||||||
|
* === Example
|
||||||
*
|
*
|
||||||
* PTY.open {|m, s|
|
* PTY.open {|m, s|
|
||||||
* p m #=> #<IO:masterpty:/dev/pts/1>
|
* p m #=> #<IO:masterpty:/dev/pts/1>
|
||||||
|
@ -465,7 +476,8 @@ pty_close_pty(VALUE assoc)
|
||||||
* w.puts "144"
|
* w.puts "144"
|
||||||
* p m.gets #=> "144: 2 2 2 2 3 3\n"
|
* p m.gets #=> "144: 2 2 2 2 3 3\n"
|
||||||
* w.close
|
* 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
|
* ret = begin
|
||||||
* m.gets # FreeBSD returns nil.
|
* m.gets # FreeBSD returns nil.
|
||||||
* rescue Errno::EIO # GNU/Linux raises EIO.
|
* rescue Errno::EIO # GNU/Linux raises EIO.
|
||||||
|
@ -513,24 +525,34 @@ pty_detach_process(struct pty_info *info)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* PTY.spawn(command...) {|r, w, pid| ... } => nil
|
* PTY.spawn(command_line) { |r, w, pid| ... }
|
||||||
* PTY.spawn(command...) => r, w, pid
|
* PTY.spawn(command_line) => [r, w, pid]
|
||||||
* PTY.getpty(command...) {|r, w, pid| ... } => nil
|
* PTY.spawn(command, args, ...) { |r, w, pid| ... }
|
||||||
* PTY.getpty(command...) => 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.
|
* 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.
|
* and its standard input/output/error is redirected to the slave device.
|
||||||
*
|
*
|
||||||
* PTY.spawn returns two IO objects and PID.
|
* <tt>command_line</tt>:: The full command line to run
|
||||||
* PID is the process ID of the command.
|
* <tt>command</tt>:: The command to run, as a String.
|
||||||
* The two IO objects are connected to the master device of the pty.
|
* <tt>args</tt>:: Zero or more arguments, as Strings, representing
|
||||||
* The first IO object is opened as read mode and
|
* the arguments to +command+
|
||||||
* The second is opened as write mode.
|
|
||||||
*
|
*
|
||||||
* If a block is given, two IO objects and PID is yielded.
|
* In the non-block form this returns an array of size three,
|
||||||
|
* <tt>[r, w, pid]</tt>. In the block form the block will be called with
|
||||||
|
* these as arguments, <tt>|r,w,pid|</tt>:
|
||||||
*
|
*
|
||||||
|
* +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
|
static VALUE
|
||||||
pty_getpty(int argc, VALUE *argv, VALUE self)
|
pty_getpty(int argc, VALUE *argv, VALUE self)
|
||||||
|
@ -599,12 +621,19 @@ raise_from_check(pid_t pid, int status)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* 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
|
* Checks the status of the child process specified by +pid+.
|
||||||
* returns +nil+ if the process is still alive and active. Otherwise,
|
* Returns +nil+ if the process is still alive. If the process
|
||||||
* returns +Process::Status+ about the process if _raise_ is false, or
|
* is not alive, will return a <tt>Process::Status</tt> or raise
|
||||||
* +PTY::ChildExited+ exception is raised.
|
* a <tt>PTY::ChildExited</tt> (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 <tt>PTY::ChildExited</tt> is raised.
|
||||||
|
*
|
||||||
|
* Returns nil or a <tt>Process::Status</tt> when +raise+ is false.
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
pty_check(int argc, VALUE *argv, VALUE self)
|
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();
|
if (!RTEST(exc)) return rb_last_status_get();
|
||||||
raise_from_check(cpid, status);
|
raise_from_check(cpid, status);
|
||||||
return Qnil; /* not reached */
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE cPTY;
|
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
|
void
|
||||||
Init_pty()
|
Init_pty()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue