Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

process.c File Reference

#include "ruby.h"
#include "rubysig.h"
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <ctype.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include "st.h"
#include <sys/times.h>
#include <grp.h>

Go to the source code of this file.

Defines

#define EXIT_SUCCESS   0
#define EXIT_FAILURE   1
#define WIFEXITED(w)   (((w) & 0xff) == 0)
#define WIFSIGNALED(w)   (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
#define WIFSTOPPED(w)   (((w) & 0xff) == 0x7f)
#define WEXITSTATUS(w)   (((w) >> 8) & 0xff)
#define WTERMSIG(w)   ((w) & 0x7f)
#define WSTOPSIG   WEXITSTATUS
#define before_exec()   rb_thread_stop_timer()
#define after_exec()   rb_thread_start_timer()
#define HZ   60

Functions

timeval rb_time_interval (VALUE)
VALUE get_pid ()
VALUE get_ppid ()
void last_status_set (int status, int pid)
VALUE pst_to_i (VALUE st)
VALUE pst_to_s (VALUE st)
VALUE pst_pid (VALUE st)
VALUE pst_inspect (VALUE st)
VALUE pst_equal (VALUE st1, VALUE st2)
VALUE pst_bitand (VALUE st1, VALUE st2)
VALUE pst_rshift (VALUE st1, VALUE st2)
VALUE pst_wifstopped (VALUE st)
VALUE pst_wstopsig (VALUE st)
VALUE pst_wifsignaled (VALUE st)
VALUE pst_wtermsig (VALUE st)
VALUE pst_wifexited (VALUE st)
VALUE pst_wexitstatus (VALUE st)
VALUE pst_success_p (VALUE st)
VALUE pst_wcoredump (VALUE st)
int rb_waitpid (int pid, int *st, int flags)
VALUE proc_wait (int argc, VALUE *argv)
VALUE proc_wait2 (int argc, VALUE *argv)
VALUE proc_waitall ()
VALUE detach_process_watcher (int *pid_p)
VALUE rb_detach_process (int pid)
VALUE proc_detach (VALUE obj, VALUE pid)
char * dln_find_exe ()
void security (char *str)
int proc_exec_v (char **argv, char *prog)
int proc_exec_n (int argc, VALUE *argv, VALUE progv)
int rb_proc_exec (char *str) const
VALUE rb_f_exec (int argc, VALUE *argv)
VALUE rb_f_fork (VALUE obj)
VALUE rb_f_exit_bang (int argc, VALUE *argv, VALUE obj)
void rb_syswait (int pid)
VALUE rb_f_system (int argc, VALUE *argv)
VALUE rb_f_sleep (int argc, VALUE *argv)
VALUE proc_getpgrp ()
VALUE proc_setpgrp ()
VALUE proc_getpgid (VALUE obj, VALUE pid)
VALUE proc_setpgid (VALUE obj, VALUE pid, VALUE pgrp)
VALUE proc_setsid ()
VALUE proc_getpriority (VALUE obj, VALUE which, VALUE who)
VALUE proc_setpriority (VALUE obj, VALUE which, VALUE who, VALUE prio)
void check_uid_switch ()
void check_gid_switch ()
VALUE p_sys_setuid (VALUE obj, VALUE id)
VALUE p_sys_setruid (VALUE obj, VALUE id)
VALUE p_sys_seteuid (VALUE obj, VALUE id)
VALUE p_sys_setreuid (VALUE obj, VALUE rid, VALUE eid)
VALUE p_sys_setresuid (VALUE obj, VALUE rid, VALUE eid, VALUE sid)
VALUE proc_getuid (VALUE obj)
VALUE proc_setuid (VALUE obj, VALUE id)
VALUE p_uid_change_privilege (VALUE obj, VALUE id)
VALUE p_sys_setgid (VALUE obj, VALUE id)
VALUE p_sys_setrgid (VALUE obj, VALUE id)
VALUE p_sys_setegid (VALUE obj, VALUE id)
VALUE p_sys_setregid (VALUE obj, VALUE rid, VALUE eid)
VALUE p_sys_setresgid (VALUE obj, VALUE rid, VALUE eid, VALUE sid)
VALUE p_sys_issetugid (VALUE obj)
VALUE proc_getgid (VALUE obj)
VALUE proc_setgid (VALUE obj, VALUE id)
VALUE proc_getgroups (VALUE obj)
VALUE proc_setgroups (VALUE obj, VALUE ary)
VALUE proc_initgroups (VALUE obj, VALUE uname, VALUE base_grp)
VALUE proc_getmaxgroups (VALUE obj)
VALUE proc_setmaxgroups (VALUE obj, VALUE val)
VALUE p_gid_change_privilege (VALUE obj, VALUE id)
VALUE proc_geteuid (VALUE obj)
VALUE proc_seteuid (VALUE obj, VALUE euid)
VALUE rb_seteuid_core (int euid)
VALUE p_uid_grant_privilege (VALUE obj, VALUE id)
VALUE proc_getegid (VALUE obj)
VALUE proc_setegid (VALUE obj, VALUE egid)
VALUE rb_setegid_core (int egid)
VALUE p_gid_grant_privilege (VALUE obj, VALUE id)
VALUE p_uid_exchangeable ()
VALUE p_uid_exchange (VALUE obj)
VALUE p_gid_exchangeable ()
VALUE p_gid_exchange (VALUE obj)
VALUE p_uid_have_saved_id ()
VALUE p_uid_sw_ensure (int id)
VALUE p_uid_switch (VALUE obj)
VALUE p_gid_have_saved_id ()
VALUE p_gid_sw_ensure (int id)
VALUE p_gid_switch (VALUE obj)
VALUE rb_proc_times (VALUE obj)
void Init_process ()

Variables

VALUE S_Tms
VALUE rb_cProcStatus
VALUE rb_last_status = Qnil
int under_uid_switch = 0
int under_gid_switch = 0
int SAVED_USER_ID
size_t maxgroups = 32
int SAVED_GROUP_ID
VALUE rb_mProcess
VALUE rb_mProcUID
VALUE rb_mProcGID
VALUE rb_mProcID_Syscall


Define Documentation

 
#define after_exec  )     rb_thread_start_timer()
 

Definition at line 915 of file process.c.

Referenced by proc_exec_v(), rb_f_fork(), and rb_proc_exec().

 
#define before_exec  )     rb_thread_stop_timer()
 

Definition at line 914 of file process.c.

Referenced by proc_exec_v(), and rb_proc_exec().

#define EXIT_FAILURE   1
 

Definition at line 37 of file process.c.

#define EXIT_SUCCESS   0
 

Definition at line 34 of file process.c.

#define HZ   60
 

Referenced by rb_proc_times().

#define WEXITSTATUS  )     (((w) >> 8) & 0xff)
 

Definition at line 76 of file process.c.

Referenced by pst_inspect(), pst_success_p(), and pst_wexitstatus().

#define WIFEXITED  )     (((w) & 0xff) == 0)
 

Definition at line 67 of file process.c.

Referenced by pst_inspect(), pst_success_p(), pst_wexitstatus(), and pst_wifexited().

#define WIFSIGNALED  )     (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
 

Definition at line 70 of file process.c.

Referenced by pst_inspect(), pst_wifsignaled(), and pst_wtermsig().

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

Definition at line 73 of file process.c.

Referenced by pst_inspect(), pst_wifstopped(), and pst_wstopsig().

#define WSTOPSIG   WEXITSTATUS
 

Definition at line 82 of file process.c.

Referenced by pst_inspect(), and pst_wstopsig().

#define WTERMSIG  )     ((w) & 0x7f)
 

Definition at line 79 of file process.c.

Referenced by pst_inspect(), and pst_wtermsig().


Function Documentation

void check_gid_switch  )  [static]
 

Definition at line 1834 of file process.c.

References rb_eRuntimeError, rb_raise(), rb_secure(), and under_gid_switch.

Referenced by p_gid_change_privilege(), p_gid_exchange(), p_gid_switch(), p_sys_setegid(), p_sys_setgid(), p_sys_setregid(), p_sys_setresgid(), p_sys_setrgid(), proc_setegid(), proc_setgid(), and rb_setegid_core().

void check_uid_switch  )  [static]
 

Definition at line 1824 of file process.c.

References rb_eRuntimeError, rb_raise(), rb_secure(), and under_uid_switch.

Referenced by p_sys_seteuid(), p_sys_setresuid(), p_sys_setreuid(), p_sys_setruid(), p_sys_setuid(), p_uid_change_privilege(), p_uid_exchange(), p_uid_switch(), proc_seteuid(), proc_setuid(), and rb_seteuid_core().

VALUE detach_process_watcher int *  pid_p  )  [static]
 

Definition at line 841 of file process.c.

References Qnil, rb_thread_sleep(), and rb_waitpid().

Referenced by rb_detach_process().

char* dln_find_exe  ) 
 

Referenced by proc_exec_v(), and rb_proc_exec().

VALUE get_pid  )  [static]
 

Definition at line 125 of file process.c.

References INT2FIX, and rb_secure().

Referenced by Init_process().

VALUE get_ppid  )  [static]
 

Definition at line 149 of file process.c.

References INT2FIX, and rb_secure().

Referenced by Init_process().

void Init_process void   ) 
 

Definition at line 3360 of file process.c.

References CLASS_OF, get_pid(), get_ppid(), INT2FIX, NULL, p_gid_change_privilege(), p_gid_exchange(), p_gid_exchangeable(), p_gid_grant_privilege(), p_gid_have_saved_id(), p_gid_switch(), p_sys_issetugid(), p_sys_setegid(), p_sys_seteuid(), p_sys_setgid(), p_sys_setregid(), p_sys_setresgid(), p_sys_setresuid(), p_sys_setreuid(), p_sys_setrgid(), p_sys_setruid(), p_sys_setuid(), p_uid_change_privilege(), p_uid_exchange(), p_uid_exchangeable(), p_uid_grant_privilege(), p_uid_have_saved_id(), p_uid_switch(), proc_detach(), proc_getegid(), proc_geteuid(), proc_getgid(), proc_getgroups(), proc_getmaxgroups(), proc_getpgid(), proc_getpgrp(), proc_getpriority(), proc_getuid(), proc_initgroups(), proc_setegid(), proc_seteuid(), proc_setgid(), proc_setgroups(), proc_setmaxgroups(), proc_setpgid(), proc_setpgrp(), proc_setpriority(), proc_setsid(), proc_setuid(), proc_wait(), proc_wait2(), proc_waitall(), pst_bitand(), pst_equal(), pst_inspect(), pst_pid(), pst_rshift(), pst_success_p(), pst_to_i(), pst_to_s(), pst_wcoredump(), pst_wexitstatus(), pst_wifexited(), pst_wifsignaled(), pst_wifstopped(), pst_wstopsig(), pst_wtermsig(), rb_cObject, rb_cProcStatus, rb_define_alias(), rb_define_class_under(), rb_define_const(), rb_define_global_function(), rb_define_method(), rb_define_module(), rb_define_module_function(), rb_define_module_under(), rb_define_readonly_variable(), rb_define_singleton_method(), rb_define_virtual_variable(), rb_f_abort(), rb_f_exec(), rb_f_exit(), rb_f_exit_bang(), rb_f_fork(), rb_f_kill(), rb_f_sleep(), rb_f_system(), rb_last_status, rb_mProcess, rb_mProcGID, rb_mProcID_Syscall, rb_mProcUID, rb_proc_times(), rb_struct_define(), rb_undef_method(), S_Tms, SAVED_GROUP_ID, and SAVED_USER_ID.

Referenced by rb_call_inits().

void last_status_set int  status,
int  pid
[static]
 

Definition at line 194 of file process.c.

References INT2FIX, rb_cProcStatus, rb_iv_set(), rb_last_status, and rb_obj_alloc().

Referenced by proc_waitall(), rb_f_system(), and rb_waitpid().

VALUE p_gid_change_privilege VALUE  obj,
VALUE  id
[static]
 

Definition at line 2608 of file process.c.

References check_gid_switch(), INT2FIX, NUM2INT, rb_notimplement(), rb_sys_fail(), SAVED_GROUP_ID, and VALUE.

Referenced by Init_process().

VALUE p_gid_exchange VALUE  obj  )  [static]
 

Definition at line 3066 of file process.c.

References check_gid_switch(), INT2FIX, rb_notimplement(), rb_sys_fail(), SAVED_GROUP_ID, and VALUE.

Referenced by Init_process(), and p_gid_switch().

VALUE p_gid_exchangeable  )  [static]
 

Definition at line 3041 of file process.c.

References Qfalse, and Qtrue.

Referenced by Init_process().

VALUE p_gid_grant_privilege VALUE  obj,
VALUE  id
[static]
 

Definition at line 2966 of file process.c.

References NUM2INT, rb_setegid_core(), and VALUE.

Referenced by Init_process().

VALUE p_gid_have_saved_id  )  [static]
 

Definition at line 3212 of file process.c.

References Qfalse, and Qtrue.

Referenced by Init_process().

VALUE p_gid_sw_ensure int  id  )  [static]
 

Definition at line 3223 of file process.c.

References rb_setegid_core(), and under_gid_switch.

Referenced by p_gid_switch().

VALUE p_gid_switch VALUE  obj  )  [static]
 

Definition at line 3245 of file process.c.

References check_gid_switch(), INT2FIX, p_gid_exchange(), p_gid_sw_ensure(), proc_setegid(), Qnil, rb_block_given_p(), rb_ensure(), rb_sys_fail(), rb_yield(), SAVED_GROUP_ID, under_gid_switch, and VALUE.

Referenced by Init_process().

VALUE p_sys_issetugid VALUE  obj  )  [static]
 

Definition at line 2330 of file process.c.

References Qfalse, Qnil, Qtrue, rb_notimplement(), rb_secure(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setegid VALUE  obj,
VALUE  id
[static]
 

Definition at line 2255 of file process.c.

References check_gid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_seteuid VALUE  obj,
VALUE  id
[static]
 

Definition at line 1911 of file process.c.

References check_uid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setgid VALUE  obj,
VALUE  id
[static]
 

Definition at line 2208 of file process.c.

References check_gid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setregid VALUE  obj,
VALUE  rid,
VALUE  eid
[static]
 

Definition at line 2280 of file process.c.

References check_gid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setresgid VALUE  obj,
VALUE  rid,
VALUE  eid,
VALUE  sid
[static]
 

Definition at line 2304 of file process.c.

References check_gid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setresuid VALUE  obj,
VALUE  rid,
VALUE  eid,
VALUE  sid
[static]
 

Definition at line 1961 of file process.c.

References check_uid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setreuid VALUE  obj,
VALUE  rid,
VALUE  eid
[static]
 

Definition at line 1936 of file process.c.

References check_uid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setrgid VALUE  obj,
VALUE  id
[static]
 

Definition at line 2231 of file process.c.

References check_gid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setruid VALUE  obj,
VALUE  id
[static]
 

Definition at line 1888 of file process.c.

References check_uid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_sys_setuid VALUE  obj,
VALUE  id
[static]
 

Definition at line 1864 of file process.c.

References check_uid_switch(), NUM2INT, Qnil, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE p_uid_change_privilege VALUE  obj,
VALUE  id
[static]
 

Definition at line 2058 of file process.c.

References check_uid_switch(), INT2FIX, NUM2INT, rb_notimplement(), rb_sys_fail(), SAVED_USER_ID, and VALUE.

Referenced by Init_process().

VALUE p_uid_exchange VALUE  obj  )  [static]
 

Definition at line 3008 of file process.c.

References check_uid_switch(), INT2FIX, rb_notimplement(), rb_sys_fail(), SAVED_USER_ID, and VALUE.

Referenced by Init_process(), and p_uid_switch().

VALUE p_uid_exchangeable  )  [static]
 

Definition at line 2983 of file process.c.

References Qfalse, and Qtrue.

Referenced by Init_process().

VALUE p_uid_grant_privilege VALUE  obj,
VALUE  id
[static]
 

Definition at line 2852 of file process.c.

References NUM2INT, rb_seteuid_core(), and VALUE.

Referenced by Init_process().

VALUE p_uid_have_saved_id  )  [static]
 

Definition at line 3100 of file process.c.

References Qfalse, and Qtrue.

Referenced by Init_process().

VALUE p_uid_sw_ensure int  id  )  [static]
 

Definition at line 3112 of file process.c.

References rb_seteuid_core(), and under_uid_switch.

Referenced by p_uid_switch().

VALUE p_uid_switch VALUE  obj  )  [static]
 

Definition at line 3134 of file process.c.

References check_uid_switch(), INT2FIX, p_uid_exchange(), p_uid_sw_ensure(), proc_seteuid(), Qnil, rb_block_given_p(), rb_ensure(), rb_sys_fail(), rb_yield(), SAVED_USER_ID, under_uid_switch, and VALUE.

Referenced by Init_process().

VALUE proc_detach VALUE  obj,
VALUE  pid
[static]
 

Definition at line 903 of file process.c.

References NUM2INT, rb_detach_process(), and rb_secure().

Referenced by Init_process().

int proc_exec_n int  argc,
VALUE argv,
VALUE  progv
[static]
 

Definition at line 990 of file process.c.

References ALLOCA_N, args, proc_exec_v(), RSTRING, SafeStringValue, and VALUE.

Referenced by rb_f_exec(), and rb_f_system().

int proc_exec_v char **  argv,
char *  prog
[static]
 

Definition at line 935 of file process.c.

References after_exec, ALLOCA_N, before_exec, dln_find_exe(), NULL, security(), strcasecmp(), and strrchr().

Referenced by proc_exec_n(), and rb_proc_exec().

VALUE proc_getegid VALUE  obj  )  [static]
 

Definition at line 2872 of file process.c.

References INT2FIX, and VALUE.

Referenced by Init_process().

VALUE proc_geteuid VALUE  obj  )  [static]
 

Definition at line 2760 of file process.c.

References INT2FIX, and VALUE.

Referenced by Init_process().

VALUE proc_getgid VALUE  obj  )  [static]
 

Definition at line 2359 of file process.c.

References INT2FIX, and VALUE.

Referenced by Init_process().

VALUE proc_getgroups VALUE  obj  )  [static]
 

Definition at line 2418 of file process.c.

References ALLOCA_N, INT2NUM, maxgroups, Qnil, rb_ary_new(), rb_ary_push(), rb_gid_t, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process(), proc_initgroups(), and proc_setgroups().

VALUE proc_getmaxgroups VALUE  obj  )  [static]
 

Definition at line 2552 of file process.c.

References INT2FIX, maxgroups, and VALUE.

Referenced by Init_process().

VALUE proc_getpgid VALUE  obj,
VALUE  pid
[static]
 

Definition at line 1661 of file process.c.

References INT2NUM, NUM2INT, rb_notimplement(), rb_secure(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE proc_getpgrp  )  [static]
 

Definition at line 1602 of file process.c.

References INT2FIX, rb_notimplement(), rb_secure(), and rb_sys_fail().

Referenced by Init_process().

VALUE proc_getpriority VALUE  obj,
VALUE  which,
VALUE  who
[static]
 

Definition at line 1770 of file process.c.

References INT2FIX, NUM2INT, rb_notimplement(), rb_secure(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE proc_getuid VALUE  obj  )  [static]
 

Definition at line 1986 of file process.c.

References INT2FIX, and VALUE.

Referenced by Init_process().

VALUE proc_initgroups VALUE  obj,
VALUE  uname,
VALUE  base_grp
[static]
 

Definition at line 2526 of file process.c.

References NUM2INT, proc_getgroups(), Qnil, rb_gid_t, rb_notimplement(), rb_sys_fail(), StringValuePtr, and VALUE.

Referenced by Init_process().

VALUE proc_setegid VALUE  obj,
VALUE  egid
[static]
 

Definition at line 2890 of file process.c.

References check_gid_switch(), NUM2INT, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process(), and p_gid_switch().

VALUE proc_seteuid VALUE  obj,
VALUE  euid
[static]
 

Definition at line 2777 of file process.c.

References check_uid_switch(), NUM2INT, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process(), and p_uid_switch().

VALUE proc_setgid VALUE  obj,
VALUE  id
[static]
 

Definition at line 2375 of file process.c.

References check_gid_switch(), INT2FIX, NUM2INT, rb_notimplement(), rb_sys_fail(), and VALUE.

Referenced by Init_process().

VALUE proc_