signal.c File Reference
`#include "ruby/ruby.h"`
`#include "vm_core.h"`
`#include <signal.h>`
`#include <stdio.h>`
`#include <errno.h>`
`#include "atomic.h"`

Go to the source code of this file.

## Data Structures

struct | signals
struct | trap_arg

## Macros

#define | USE_TRAP_MASK 0
#define | killpg(pg, sig) kill(-(pg), (sig))
#define | SIGINFO_ARG
#define | ruby_signal(sig, handler) (/* rb_trap_accept_nativethreads[(sig)] = 0,*/ signal((sig),(handler)))
#define | ruby_enable_coredump 0

## Typedefs

typedef RETSIGTYPE(* | sighandler_t )(int)
typedef RETSIGTYPE | ruby_sigaction_t (int)

## Functions

rb_atomic_t | ruby_atomic_exchange (rb_atomic_t *ptr, rb_atomic_t val)
static int | signm2signo (const char *nm)
static const char * | signo2signm (int no)
const char * | ruby_signal_name (int no)
static VALUE | esignal_init (int argc, VALUE *argv, VALUE self)
static VALUE | esignal_signo (VALUE self)
static VALUE | interrupt_init (int argc, VALUE *argv, VALUE self)
void | ruby_default_signal (int sig)
VALUE | rb_f_kill (int argc, VALUE *argv)
static RETSIGTYPE | sighandler (int sig)
int | rb_signal_buff_size (void)
void | rb_disable_interrupt (void)
void | rb_enable_interrupt (void)
int | rb_get_next_signal (void)
static void | signal_exec (VALUE cmd, int safe, int sig)
void | rb_trap_exit (void)
void | rb_signal_exec (rb_thread_t *th, int sig)
static sighandler_t | default_handler (int sig)
static sighandler_t | trap_handler (VALUE *cmd, int sig)
static int | trap_signm (VALUE vsig)
static VALUE | trap (struct trap_arg *arg)
void | rb_trap_restore_mask (void)
static VALUE | sig_trap (int argc, VALUE *argv)
static VALUE | sig_list (void)
static void | install_sighandler (int signum, sighandler_t handler)
void | ruby_sig_finalize (void)
void | Init_signal (void)

## Variables

static struct signals | siglist []
struct {
rb_atomic_t cnt [RUBY_NSIG]
rb_atomic_t size
} | signal_buff
int | ruby_enable_coredump = 0

## Macro Definition Documentation

#define killpg | ( |  | pg,
|  |  | sig
| ) |  | kill(-(pg), (sig))

Referenced by rb_f_kill().

#define ruby_enable_coredump 0

Definition at line 1025 of file signal.c.

#define ruby_signal | ( |  | sig,
|  |  | handler
| ) |  | (/* rb_trap_accept_nativethreads[(sig)] = 0,*/ signal((sig),(handler)))

Definition at line 484 of file signal.c.

Referenced by install_sighandler(), ruby_sig_finalize(), sighandler(), and trap().

#define SIGINFO_ARG

Definition at line 420 of file signal.c.

#define USE_TRAP_MASK 0

Definition at line 38 of file signal.c.

## Typedef Documentation

typedef RETSIGTYPE ruby_sigaction_t(int)

Definition at line 419 of file signal.c.

typedef RETSIGTYPE(* sighandler_t)(int)

Definition at line 414 of file signal.c.

## Function Documentation

static sighandler_t default_handler | ( | int | sig | ) |

static

Definition at line 685 of file signal.c.

References func, GET_THREAD, sighandler(), and SIGINT.

Referenced by trap_handler().

static VALUE esignal_init | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | self
| ) |  |

static

Definition at line 222 of file signal.c.

References INT2NUM(), NIL_P, NSIG, NUM2INT, Qnil, rb_call_super(), rb_check_to_integer(), rb_eArgError, rb_id2name(), rb_iv_set(), rb_raise(), rb_sprintf(), signals::signm, signm2signo(), signals::signo, signo2signm(), StringValuePtr, SYM2ID, and SYMBOL_P.

Referenced by Init_signal().

static VALUE esignal_signo | ( | VALUE | self | ) |

static

Definition at line 279 of file signal.c.

References rb_iv_get().

Referenced by Init_signal().

void Init_signal | ( | void |  | ) |

Definition at line 1066 of file signal.c.

References esignal_init(), esignal_signo(), GET_THREAD, install_sighandler(), interrupt_init(), rb_alias(), rb_define_global_function(), rb_define_method(), rb_define_module(), rb_define_module_function(), rb_eInterrupt, rb_eSignal, rb_intern, sig_list(), sig_trap(), sighandler(), and SIGINT.

static void install_sighandler | ( | int | signum,
|  | sighandler_t | handler
| ) |  |

static

Definition at line 972 of file signal.c.

References ruby_signal.

Referenced by Init_signal().

static VALUE interrupt_init | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | self
| ) |  |

static

Definition at line 286 of file signal.c.

References args, INT2FIX, rb_call_super(), rb_scan_args(), and SIGINT.

Referenced by Init_signal().

void rb_disable_interrupt | ( | void |  | ) |

Definition at line 524 of file signal.c.

References NULL, and pthread_sigmask().

Referenced by after_exec(), and rb_get_next_signal().

void rb_enable_interrupt | ( | void |  | ) |

Definition at line 536 of file signal.c.

References NULL, and pthread_sigmask().

Referenced by before_exec(), and rb_get_next_signal().

VALUE rb_f_kill | ( | int | argc,
|  | VALUE * | argv
| ) |  |

Definition at line 337 of file signal.c.

References argc, FIX2INT, i, INT2FIX, kill(), killpg, NIL_P, NUM2PIDT, rb_check_string_type(), rb_eArgError, rb_id2name(), rb_obj_classname(), rb_raise(), rb_secure(), rb_sys_fail(), rb_thread_polling(), RSTRING_PTR, signm2signo(), SYM2ID, T_FIXNUM, T_STRING, T_SYMBOL, and TYPE.

Referenced by Init_process().

int rb_get_next_signal | ( | void |  | ) |

Definition at line 546 of file signal.c.

References ATOMIC_DEC, i, rb_disable_interrupt(), rb_enable_interrupt(), RUBY_NSIG, and signal_buff.

Referenced by rb_threadptr_execute_interrupts_common().

int rb_signal_buff_size | ( | void |  | ) |

Definition at line 510 of file signal.c.

References signal_buff.

Referenced by rb_thread_check_trap_pending(), and rb_threadptr_check_signal().

void rb_signal_exec | ( | rb_thread_t * | th,
|  | int | sig
| ) |  |

Definition at line 634 of file signal.c.

References rb_vm_struct::cmd, GET_VM, Qundef, rb_interrupt(), rb_threadptr_signal_exit(), rb_threadptr_signal_raise(), rb_vm_struct::safe, SIGINT, signal_exec(), and rb_vm_struct::trap_list.

Referenced by rb_threadptr_execute_interrupts_common().

void rb_trap_exit | ( | void |  | ) |

Definition at line 622 of file signal.c.

References rb_vm_struct::cmd, GET_VM, rb_vm_struct::safe, signal_exec(), and rb_vm_struct::trap_list.

Referenced by ruby_finalize_0().

void rb_trap_restore_mask | ( | void |  | ) |

Definition at line 874 of file signal.c.

References NULL, and pthread_sigmask().

Referenced by rb_throw_obj(), and setup_exception().

rb_atomic_t ruby_atomic_exchange | ( | rb_atomic_t * | ptr,
|  | rb_atomic_t | val
| ) |  |

Definition at line 23 of file signal.c.

void ruby_default_signal | ( | int | sig | ) |

Definition at line 296 of file signal.c.

References signal().

Referenced by ruby_cleanup().

void ruby_sig_finalize | ( | void |  | ) |

Definition at line 1012 of file signal.c.

References ruby_signal, sighandler(), and SIGINT.

Referenced by ruby_finalize_1().

const char* ruby_signal_name | ( | int | no | ) |

Definition at line 207 of file signal.c.

References signo2signm().

Referenced by pst_message().

static VALUE sig_list | ( | void |  | ) |

static

Definition at line 960 of file signal.c.

References INT2FIX, rb_hash_aset(), rb_hash_new(), rb_str_new2(), siglist, signals::signm, and signals::signo.

Referenced by Init_signal().

static VALUE sig_trap | ( | int | argc,
|  | VALUE * | argv
| ) |  |

static

Definition at line 913 of file signal.c.

References trap_arg::cmd, trap_arg::func, OBJ_TAINTED, pthread_sigmask(), rb_block_proc(), rb_eArgError, rb_ensure(), rb_eSecurityError, rb_raise(), rb_secure(), trap_arg::sig, sighandler(), trap(), trap_handler(), and trap_signm().

Referenced by Init_signal().

static RETSIGTYPE sighandler | ( | int | sig | ) |

static

Definition at line 499 of file signal.c.

References ATOMIC_INC, rb_thread_wakeup_timer_thread(), ruby_signal, and signal_buff.

Referenced by default_handler(), Init_signal(), ruby_sig_finalize(), sig_trap(), trap(), and trap_handler().

static void signal_exec | ( | VALUE | cmd,
|  | int | safe,
|  | int | sig
| ) |  |

static

Definition at line 615 of file signal.c.

References INT2NUM(), rb_ary_new3(), and rb_eval_cmd().

Referenced by rb_signal_exec(), and rb_trap_exit().

static int signm2signo | ( | const char * | nm | ) |

static

Definition at line 185 of file signal.c.

References siglist, signals::signm, and signals::signo.

Referenced by esignal_init(), rb_f_kill(), and trap_signm().

static const char* signo2signm | ( | int | no | ) |

static

Definition at line 196 of file signal.c.

References siglist, signals::signm, and signals::signo.

Referenced by esignal_init(), and ruby_signal_name().

static VALUE trap | ( | struct trap_arg * | arg | ) |

static

Definition at line 833 of file signal.c.

References rb_vm_struct::cmd, trap_arg::cmd, func, trap_arg::func, GET_VM, Qnil, Qundef, rb_safe_level, rb_str_new2(), ruby_signal, rb_vm_struct::safe, trap_arg::sig, sighandler(), and rb_vm_struct::trap_list.

Referenced by sig_trap().

static sighandler_t trap_handler | ( | VALUE * | cmd,
|  | int | sig
| ) |  |

static

Definition at line 737 of file signal.c.

References default_handler(), func, GetProcPtr, NIL_P, Qundef, rb_check_string_type(), rb_eArgError, rb_id2str(), rb_raise(), RSTRING_LEN, RSTRING_PTR, SafeStringValue, sighandler(), SYM2ID, and SYMBOL_P.

Referenced by sig_trap().

static int trap_signm | ( | VALUE | vsig | ) |

static

Definition at line 801 of file signal.c.

References FIX2INT, NSIG, rb_eArgError, rb_id2name(), rb_raise(), signm2signo(), StringValuePtr, SYM2ID, T_FIXNUM, T_SYMBOL, and TYPE.

Referenced by sig_trap().

## Variable Documentation

rb_atomic_t cnt[RUBY_NSIG]

Definition at line 406 of file signal.c.

Referenced by compile_dregx(), compile_dstr(), compile_dstr_fragments(), ip_init(), local_tbl_gen(), rb_ary_rotate_m(), rb_parser_calloc(), rb_parser_malloc(), rb_parser_realloc(), swallow(), vtable_tblcpy(), and warn_unused_var().

int ruby_enable_coredump = 0

Definition at line 1023 of file signal.c.

Referenced by set_debug_option().

struct signals siglist[]

static

Referenced by sig_list(), signm2signo(), and signo2signm().

struct { ... } signal_buff

Referenced by rb_get_next_signal(), rb_signal_buff_size(), and sighandler().

rb_atomic_t size

Definition at line 407 of file signal.c.