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 "internal.h"
#include <signal.h>

Go to the source code of this file.

Data Structures

struct  pty_info
struct  child_info

Defines

#define WIFSTOPPED(status)   (((status) & 0xff) == 0x7f)
#define DEVICELEN   16
#define ERROR_EXIT(str)

Functions

static VALUE echild_status (VALUE self)
static void getDevice (int *, int *, char[DEVICELEN], int)
static int chfunc (void *data, char *errbuf, size_t errbuf_len)
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)
 NORETURN (static void raise_from_check(rb_pid_t pid, int status))
static void raise_from_check (rb_pid_t pid, int status)
static VALUE pty_check (int argc, VALUE *argv, VALUE self)
void Init_pty ()

Variables

static VALUE eChildExited
static VALUE cPTY


Define Documentation

#define DEVICELEN   16

Definition at line 50 of file pty.c.

Referenced by pty_getpty(), and pty_open().

#define ERROR_EXIT ( str   ) 

Value:

do { \
        strlcpy(errbuf, (str), errbuf_len); \
        return -1; \
    } while (0)

Referenced by chfunc().

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

Definition at line 32 of file pty.c.

Referenced by pst_message(), pst_wifstopped(), pst_wstopsig(), and raise_from_check().


Function Documentation

static int chfunc ( void *  data,
char *  errbuf,
size_t  errbuf_len 
) [static]

Definition at line 90 of file pty.c.

References dup2(), child_info::eargp, ERROR_EXIT, getuid(), ioctl(), child_info::master, rb_cloexec_open(), rb_exec_async_signal_safe(), rb_update_max_fd(), seteuid(), child_info::slave, and child_info::slavename.

Referenced by establishShell().

static VALUE echild_status ( VALUE  self  )  [static]

Definition at line 70 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 155 of file pty.c.

References chfunc(), pty_info::child_pid, child_info::eargp, errno, child_info::execarg_obj, pty_info::fd, getDevice(), getenv, getuid(), child_info::master, NULL, Qnil, rb_execarg_fixup(), rb_execarg_get(), rb_execarg_new(), rb_fork_async_signal_safe(), RB_GC_GUARD, rb_jump_tag(), rb_pid_t, rb_str_new2, rb_sys_fail(), child_info::slave, child_info::slavename, and VALUE.

Referenced by pty_getpty().

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

Definition at line 223 of file pty.c.

References chown(), getgid(), getuid(), ioctl(), mode_t, name, no_mesg(), NULL, O_CLOEXEC, rb_cloexec_open(), rb_eRuntimeError, rb_fd_fix_cloexec(), rb_raise(), rb_update_max_fd(), signal(), snprintf, and strlcpy().

Referenced by getDevice().

static void getDevice ( int *  ,
int *  ,
char  [DEVICELEN],
int   
) [static]

Definition at line 454 of file pty.c.

References get_device_once(), and rb_gc().

Referenced by establishShell(), and pty_open().

void Init_pty (  ) 

Definition at line 743 of file pty.c.

References 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 214 of file pty.c.

Referenced by get_device_once().

NORETURN ( static void   raise_from_check(rb_pid_t pid, int status)  ) 

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

Definition at line 658 of file pty.c.

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

Referenced by Init_pty().

static VALUE pty_close_pty ( VALUE  assoc  )  [static]

Definition at line 463 of file pty.c.

References Qnil, rb_ary_entry(), rb_io_close(), RB_TYPE_P, RFILE, T_FILE, and VALUE.

Referenced by pty_open().

static VALUE pty_detach_process ( struct pty_info info  )  [static]

Definition at line 539 of file pty.c.

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

Referenced by pty_getpty().

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

Definition at line 574 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_cloexec_dup(), rb_ensure(), rb_io_mode_flags, rb_obj_alloc(), rb_obj_freeze(), rb_str_new_cstr(), rb_sys_fail(), rb_update_max_fd(), rb_yield(), and VALUE.

Referenced by Init_pty().

static VALUE pty_open ( VALUE  klass  )  [static]

Definition at line 509 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(), rb_yield(), and VALUE.

Referenced by Init_pty().

static void raise_from_check ( rb_pid_t  pid,
int  status 
) [static]

Definition at line 613 of file pty.c.

References eChildExited, kill(), msg, rb_exc_new_str(), rb_exc_raise(), rb_iv_set(), rb_last_status_get(), rb_sprintf(), VALUE, and WIFSTOPPED.

Referenced by pty_check().


Variable Documentation

VALUE cPTY [static]

Definition at line 674 of file pty.c.

VALUE eChildExited [static]

Definition at line 64 of file pty.c.

Referenced by Init_pty(), and raise_from_check().


Generated on 19 Jul 2016 for Ruby by  doxygen 1.4.7