Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Defines | Functions | Variables

# ext/pty/pty.c File Reference

`#include "ruby/config.h"`
`#include <stdlib.h>`
`#include <stdio.h>`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include <sys/file.h>`
`#include <fcntl.h>`
`#include <errno.h>`
`#include <pwd.h>`
`#include <ctype.h>`
`#include "ruby/ruby.h"`
`#include "ruby/io.h"`
`#include "ruby/util.h"`
`#include <signal.h>`
Include dependency graph for pty.c:

Go to the source code of this file.

## Data Structures
struct | pty_info
struct | exec_info
struct | child_info
## Defines
#define | WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
#define | DEVICELEN 16
## Functions
static VALUE | echild_status (VALUE self)
static void | getDevice (int *, int *, char[DEVICELEN], int)
static VALUE | pty_exec (VALUE v)
static int | chfunc (void *data)
static void | establishShell (int argc, VALUE *argv, struct pty_info *info, char SlaveName[DEVICELEN])
static int | no_mesg (char *slavedevice, int nomesg)
static int | get_device_once (int *master, int *slave, char SlaveName[DEVICELEN], int nomesg, int fail)
static VALUE | pty_close_pty (VALUE assoc)
static VALUE | pty_open (VALUE klass)
static VALUE | pty_detach_process (struct pty_info *info)
static VALUE | pty_getpty (int argc, VALUE *argv, VALUE self)
static void | raise_from_check (pid_t pid, int status)
static VALUE | pty_check (int argc, VALUE *argv, VALUE self)
void | Init_pty ()
## Variables
static const char | MasterDevice [] = "/dev/pty%s"
static const char | SlaveDevice [] = "/dev/tty%s"
static const char *const | deviceNo []
static VALUE | eChildExited
static VALUE | cPTY

## Define Documentation

#define DEVICELEN 16

Definition at line 45 of file pty.c.

Referenced by get_device_once(), pty_getpty(), and pty_open().

#define WIFSTOPPED | ( |  | status | ) | (((status) & 0xff) == 0x7f)

Definition at line 28 of file pty.c.

Referenced by raise_from_check().

## Function Documentation

static int chfunc | ( | void * | data | ) | `[static]`

Definition at line 158 of file pty.c.

References exec_info::argc, child_info::argc, argc, exec_info::argv, child_info::argv, argv, dup2(), getuid(), ioctl(), child_info::master, pty_exec(), rb_protect(), rb_sys_fail(), rb_thread_atfork_before_exec(), child_info::slave, and child_info::slavename.

Referenced by establishShell(), and rb_f_system().

static VALUE echild_status | ( | VALUE | self | ) | `[static]`

Definition at line 126 of file pty.c.

References rb_intern, and rb_ivar_get().

Referenced by Init_pty().

static void establishShell | ( | int | argc,
|  | VALUE * | argv,
|  | struct pty_info * | info,
|  | char | SlaveName[DEVICELEN]
| ) |  | `[static]`

Definition at line 228 of file pty.c.

References argc, child_info::argc, argv, child_info::argv, chfunc(), pty_info::child_pid, pty_info::fd, getDevice(), getenv(), getuid(), child_info::master, NULL, Qnil, rb_fork(), rb_str_new2(), rb_sys_fail(), child_info::slave, and child_info::slavename.

Referenced by pty_getpty().

static int get_device_once | ( | int * | master,
|  | int * | slave,
|  | char | SlaveName[DEVICELEN],
|  | int | nomesg,
|  | int | fail
| ) |  | `[static]`

Definition at line 288 of file pty.c.

References chown(), DEVICELEN, deviceNo, getgid(), getuid(), ioctl(), MasterDevice, mode_t, name, no_mesg(), NULL, rb_eRuntimeError, rb_raise(), signal(), SlaveDevice, snprintf, and strlcpy().

Referenced by getDevice().

static void getDevice | ( | int * | master,
|  | int * | slave,
|  | char | SlaveName[DEVICELEN],
|  | int | nomesg
| ) |  | `[static]`

Definition at line 418 of file pty.c.

References get_device_once(), and rb_gc().

Referenced by establishShell(), and pty_open().

void Init_pty | ( |  | ) |

Definition at line 638 of file pty.c.

References cPTY, echild_status(), eChildExited, pty_check(), pty_getpty(), pty_open(), rb_define_class_under(), rb_define_method(), rb_define_module(), rb_define_module_function(), rb_define_singleton_method(), and rb_eRuntimeError.

static int no_mesg | ( | char * | slavedevice,
|  | int | nomesg
| ) |  | `[static]`

Definition at line 279 of file pty.c.

Referenced by get_device_once().

static VALUE pty_check | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | self
| ) |  | `[static]`

Definition at line 620 of file pty.c.

References NUM2PIDT, Qnil, raise_from_check(), rb_last_status_get(), rb_scan_args(), rb_waitpid(), RTEST, and WNOHANG.

Referenced by Init_pty().

static VALUE pty_close_pty | ( | VALUE | assoc | ) | `[static]`

Definition at line 427 of file pty.c.

References Qnil, rb_ary_entry(), rb_io_close(), RFILE, T_FILE, and TYPE.

Referenced by pty_open().

static VALUE pty_detach_process | ( | struct pty_info * | info | ) | `[static]`

Definition at line 518 of file pty.c.

References pty_info::child_pid, Qnil, and rb_detach_process().

Referenced by pty_getpty().

static VALUE pty_exec | ( | VALUE | v | ) | `[static]`

Definition at line 144 of file pty.c.

References exec_info::argc, exec_info::argv, and rb_f_exec().

Referenced by chfunc().

static VALUE pty_getpty | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | self
| ) |  | `[static]`

Definition at line 546 of file pty.c.

References pty_info::child_pid, DEVICELEN, establishShell(), pty_info::fd, FMODE_SYNC, MakeOpenFile, PIDT2NUM, pty_detach_process(), Qnil, rb_ary_new2(), rb_ary_store(), rb_block_given_p(), rb_cFile, rb_ensure(), rb_io_mode_flags, rb_obj_alloc(), rb_obj_freeze(), rb_str_new_cstr(), rb_sys_fail(), and rb_yield().

Referenced by Init_pty().

static VALUE pty_open | ( | VALUE | klass | ) | `[static]`

Definition at line 488 of file pty.c.

References DEVICELEN, rb_io_t::fd, FMODE_DUPLEX, FMODE_READWRITE, FMODE_SYNC, FMODE_TTY, getDevice(), MakeOpenFile, rb_io_t::mode, rb_io_t::pathv, pty_close_pty(), rb_assoc_new(), rb_block_given_p(), rb_cFile, rb_cIO, rb_ensure(), rb_obj_alloc(), rb_obj_freeze(), rb_sprintf(), rb_str_new_cstr(), and rb_yield().

Referenced by Init_pty().

static void raise_from_check | ( | pid_t | pid,
|  | int | status
| ) |  | `[static]`

Definition at line 583 of file pty.c.

References buf, eChildExited, kill(), rb_exc_new2(), rb_exc_raise(), rb_iv_set(), rb_last_status_get(), snprintf, and WIFSTOPPED.

Referenced by pty_check().

## Variable Documentation

VALUE cPTY`[static]`

Definition at line 635 of file pty.c.

Referenced by Init_pty().

const char * const deviceNo[]

Initial value:

     {
                    "p0","p1","p2","p3","p4","p5","p6","p7",
                    "p8","p9","pa","pb","pc","pd","pe","pf",
                    "q0","q1","q2","q3","q4","q5","q6","q7",
                    "q8","q9","qa","qb","qc","qd","qe","qf",
                    "r0","r1","r2","r3","r4","r5","r6","r7",
                    "r8","r9","ra","rb","rc","rd","re","rf",
                    "s0","s1","s2","s3","s4","s5","s6","s7",
                    "s8","s9","sa","sb","sc","sd","se","sf",
                    0,
            }

Definition at line 97 of file pty.c.

Referenced by get_device_once().

VALUE eChildExited`[static]`

Definition at line 123 of file pty.c.

Referenced by Init_pty(), and raise_from_check().

const char MasterDevice[] = "/dev/pty%s"`[static]`

Definition at line 95 of file pty.c.

Referenced by get_device_once().

const char SlaveDevice[] = "/dev/tty%s"

Definition at line 96 of file pty.c.

Referenced by get_device_once().