Project

General

Profile

Bug #4756 ยป 0002-Clean-up-docs-for-pty.patch

davetron5000 (David Copeland), 05/22/2011 04:27 AM

View differences:

ext/pty/README.rdoc
Code useful for creating and managing PTYs[http://en.wikipedia.org/wiki/Pseudo_terminal]
See PTY for more info
ext/pty/pty.c
# endif /* HAVE_SETREUID */
#endif /* NO_SETEUID */
static VALUE eChildExited;
static VALUE eChildExited;
/* Returns the exit status of the child for which PTY#check
* raised this exception
*/
static VALUE
echild_status(VALUE self)
{
......
rb_pid_t child_pid;
};
/**
* Document-class: PTY
*
* Creates and managed pseudo terminals (ptys).
*/
static void getDevice(int*, int*, char [DEVICELEN], int);
struct child_info {
......
*
* 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, <tt>[master_io,slave_file]</tt>.
*
* 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 <tt>|master_io,slave_file|</tt>
* and the value of the block is returned from +open+.
* The arguments are both closed after the block completes if
* they haven't been already closed.
*
* The path name of the terminal device can be gotten by slave_file.path.
* 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|
* p m #=> #<IO:masterpty:/dev/pts/1>
......
/*
* 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.
* 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]
*
* 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.
* Spawns the specified command on a newly allocated pty.
*
* 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.
* 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.
*
* If a block is given, two IO objects and PID is yielded.
* <tt>command_line...</tt>:: the full command line to run
* <tt>command</tt>:: the command to run, as a String.
* <tt>args...</tt>:: zero or more arguments, as Strings, representing
* the arguments to +command+
*
* 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 given
* 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+:: a process identifier for the command.
*/
static VALUE
pty_getpty(int argc, VALUE *argv, VALUE self)
......
/*
* call-seq:
* PTY.check(pid[, raise=false]) => Process::Status or nil
* PTY.check(pid) => 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 <tt>Process::Status</tt> or raise
* 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>.
*/
static VALUE
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;
// Since this is the last comment, it gets used by default for
// classes with no docs, and I can't seem to give ChildExited
// an explicit doc, so this hack seems to work.
/**
* Thrown when PTY#check is called for a pid
* that represents a process that has exited.
*/
void
Init_pty()
{
    (1-1/1)