2000-05-09 08:53:16 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
signal.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Tue Dec 20 10:13:44 JST 1994
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-25 07:29:39 +04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
2000-05-01 13:42:38 +04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 08:53:16 +04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
2000-05-01 13:42:38 +04:00
|
|
|
|
2000-05-09 08:53:16 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
#include "vm_core.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2008-12-04 07:57:58 +03:00
|
|
|
#include <errno.h>
|
2012-11-09 20:05:07 +04:00
|
|
|
#include "ruby_atomic.h"
|
2012-11-26 12:05:49 +04:00
|
|
|
#include "eval_intern.h"
|
2013-03-19 08:40:22 +04:00
|
|
|
#include "internal.h"
|
2013-05-14 19:44:14 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2011-06-11 18:27:08 +04:00
|
|
|
|
2013-07-12 11:37:31 +04:00
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
# include <valgrind/memcheck.h>
|
|
|
|
# ifndef VALGRIND_MAKE_MEM_DEFINED
|
|
|
|
# define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n))
|
|
|
|
# endif
|
|
|
|
# ifndef VALGRIND_MAKE_MEM_UNDEFINED
|
|
|
|
# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n))
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# define VALGRIND_MAKE_MEM_DEFINED(p, n) 0
|
|
|
|
# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
|
|
|
|
#endif
|
|
|
|
|
2012-05-17 06:48:59 +04:00
|
|
|
#if defined(__native_client__) && defined(NACL_NEWLIB)
|
|
|
|
# include "nacl/signal.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-27 14:21:59 +04:00
|
|
|
#ifdef NEED_RUBY_ATOMIC_OPS
|
2011-06-23 08:33:13 +04:00
|
|
|
rb_atomic_t
|
|
|
|
ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val)
|
2011-06-11 18:27:08 +04:00
|
|
|
{
|
|
|
|
rb_atomic_t old = *ptr;
|
|
|
|
*ptr = val;
|
|
|
|
return old;
|
2012-11-27 14:21:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_atomic_t
|
|
|
|
ruby_atomic_compare_and_swap(rb_atomic_t *ptr, rb_atomic_t cmp,
|
|
|
|
rb_atomic_t newval)
|
|
|
|
{
|
|
|
|
rb_atomic_t old = *ptr;
|
|
|
|
if (old == cmp) {
|
2013-10-26 14:07:11 +04:00
|
|
|
*ptr = newval;
|
2012-11-27 14:21:59 +04:00
|
|
|
}
|
|
|
|
return old;
|
2011-06-11 18:27:08 +04:00
|
|
|
}
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
#endif
|
|
|
|
|
2010-01-25 06:06:06 +03:00
|
|
|
#if defined(__BEOS__) || defined(__HAIKU__)
|
1999-01-20 07:59:39 +03:00
|
|
|
#undef SIGBUS
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifndef NSIG
|
2008-10-04 17:25:12 +04:00
|
|
|
# define NSIG (_SIGMAX + 1) /* For QNX */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2008-04-26 12:30:22 +04:00
|
|
|
static const struct signals {
|
2005-11-08 11:49:45 +03:00
|
|
|
const char *signm;
|
1998-01-16 15:13:05 +03:00
|
|
|
int signo;
|
|
|
|
} siglist [] = {
|
2005-06-12 20:56:06 +04:00
|
|
|
{"EXIT", 0},
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef SIGHUP
|
2002-04-24 08:54:16 +04:00
|
|
|
{"HUP", SIGHUP},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2002-04-24 08:54:16 +04:00
|
|
|
{"INT", SIGINT},
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef SIGQUIT
|
2002-04-24 08:54:16 +04:00
|
|
|
{"QUIT", SIGQUIT},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
2002-04-24 08:54:16 +04:00
|
|
|
{"ILL", SIGILL},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
2002-04-24 08:54:16 +04:00
|
|
|
{"TRAP", SIGTRAP},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
2002-04-24 08:54:16 +04:00
|
|
|
{"ABRT", SIGABRT},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2013-03-25 09:39:29 +04:00
|
|
|
#ifdef SIGIOT
|
|
|
|
{"IOT", SIGIOT},
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef SIGEMT
|
2002-04-24 08:54:16 +04:00
|
|
|
{"EMT", SIGEMT},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
2002-04-24 08:54:16 +04:00
|
|
|
{"FPE", SIGFPE},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGKILL
|
2002-04-24 08:54:16 +04:00
|
|
|
{"KILL", SIGKILL},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
2002-04-24 08:54:16 +04:00
|
|
|
{"BUS", SIGBUS},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
2002-04-24 08:54:16 +04:00
|
|
|
{"SEGV", SIGSEGV},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
2002-04-24 08:54:16 +04:00
|
|
|
{"SYS", SIGSYS},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
2002-04-24 08:54:16 +04:00
|
|
|
{"PIPE", SIGPIPE},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
2002-04-24 08:54:16 +04:00
|
|
|
{"ALRM", SIGALRM},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
2002-04-24 08:54:16 +04:00
|
|
|
{"TERM", SIGTERM},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
2002-04-24 08:54:16 +04:00
|
|
|
{"URG", SIGURG},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSTOP
|
2002-04-24 08:54:16 +04:00
|
|
|
{"STOP", SIGSTOP},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
2002-04-24 08:54:16 +04:00
|
|
|
{"TSTP", SIGTSTP},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
2002-04-24 08:54:16 +04:00
|
|
|
{"CONT", SIGCONT},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
2002-04-24 08:54:16 +04:00
|
|
|
{"CHLD", SIGCHLD},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCLD
|
2002-04-24 08:54:16 +04:00
|
|
|
{"CLD", SIGCLD},
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
|
|
|
# ifdef SIGCHLD
|
2002-04-24 08:54:16 +04:00
|
|
|
{"CLD", SIGCHLD},
|
1998-01-16 15:13:05 +03:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
2002-04-24 08:54:16 +04:00
|
|
|
{"TTIN", SIGTTIN},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
2002-04-24 08:54:16 +04:00
|
|
|
{"TTOU", SIGTTOU},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
2002-04-24 08:54:16 +04:00
|
|
|
{"IO", SIGIO},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
2002-04-24 08:54:16 +04:00
|
|
|
{"XCPU", SIGXCPU},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXFSZ
|
2002-04-24 08:54:16 +04:00
|
|
|
{"XFSZ", SIGXFSZ},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGVTALRM
|
2002-04-24 08:54:16 +04:00
|
|
|
{"VTALRM", SIGVTALRM},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
2002-04-24 08:54:16 +04:00
|
|
|
{"PROF", SIGPROF},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
2002-04-24 08:54:16 +04:00
|
|
|
{"WINCH", SIGWINCH},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
2002-04-24 08:54:16 +04:00
|
|
|
{"USR1", SIGUSR1},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
2002-04-24 08:54:16 +04:00
|
|
|
{"USR2", SIGUSR2},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGLOST
|
2002-04-24 08:54:16 +04:00
|
|
|
{"LOST", SIGLOST},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGMSG
|
2002-04-24 08:54:16 +04:00
|
|
|
{"MSG", SIGMSG},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
2002-04-24 08:54:16 +04:00
|
|
|
{"PWR", SIGPWR},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPOLL
|
2002-04-24 08:54:16 +04:00
|
|
|
{"POLL", SIGPOLL},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGDANGER
|
2002-04-24 08:54:16 +04:00
|
|
|
{"DANGER", SIGDANGER},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGMIGRATE
|
2002-04-24 08:54:16 +04:00
|
|
|
{"MIGRATE", SIGMIGRATE},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPRE
|
2002-04-24 08:54:16 +04:00
|
|
|
{"PRE", SIGPRE},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGGRANT
|
2002-04-24 08:54:16 +04:00
|
|
|
{"GRANT", SIGGRANT},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGRETRACT
|
2002-04-24 08:54:16 +04:00
|
|
|
{"RETRACT", SIGRETRACT},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSOUND
|
2002-04-24 08:54:16 +04:00
|
|
|
{"SOUND", SIGSOUND},
|
2001-05-16 13:05:54 +04:00
|
|
|
#endif
|
|
|
|
#ifdef SIGINFO
|
2002-04-24 08:54:16 +04:00
|
|
|
{"INFO", SIGINFO},
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2002-04-24 08:54:16 +04:00
|
|
|
{NULL, 0}
|
1998-01-16 15:13:05 +03:00
|
|
|
};
|
|
|
|
|
2014-03-31 06:34:43 +04:00
|
|
|
static const char signame_prefix[3] = "SIG";
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
2005-11-08 11:49:45 +03:00
|
|
|
signm2signo(const char *nm)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-26 12:30:22 +04:00
|
|
|
const struct signals *sigs;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
for (sigs = siglist; sigs->signm; sigs++)
|
|
|
|
if (strcmp(sigs->signm, nm) == 0)
|
|
|
|
return sigs->signo;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-08 11:49:45 +03:00
|
|
|
static const char*
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
signo2signm(int no)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2008-04-26 12:30:22 +04:00
|
|
|
const struct signals *sigs;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
for (sigs = siglist; sigs->signm; sigs++)
|
|
|
|
if (sigs->signo == no)
|
|
|
|
return sigs->signm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-19 13:43:53 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Signal.signame(signo) -> string
|
|
|
|
*
|
|
|
|
* convert signal number to signal name
|
|
|
|
*
|
|
|
|
* Signal.trap("INT") { |signo| puts Signal.signame(signo) }
|
|
|
|
* Process.kill("INT", 0)
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* INT
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
sig_signame(VALUE recv, VALUE signo)
|
|
|
|
{
|
|
|
|
const char *signame = signo2signm(NUM2INT(signo));
|
|
|
|
return rb_str_new_cstr(signame);
|
|
|
|
}
|
|
|
|
|
2003-10-01 19:14:23 +04:00
|
|
|
const char *
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ruby_signal_name(int no)
|
2003-09-29 06:44:49 +04:00
|
|
|
{
|
|
|
|
return signo2signm(no);
|
|
|
|
}
|
|
|
|
|
2007-04-19 21:37:03 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* SignalException.new(sig_name) -> signal_exception
|
|
|
|
* SignalException.new(sig_number [, name]) -> signal_exception
|
2007-04-19 21:37:03 +04:00
|
|
|
*
|
2010-04-30 08:35:16 +04:00
|
|
|
* Construct a new SignalException object. +sig_name+ should be a known
|
|
|
|
* signal name.
|
2007-04-19 21:37:03 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
esignal_init(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
int argnum = 1;
|
|
|
|
VALUE sig = Qnil;
|
|
|
|
int signo;
|
|
|
|
const char *signm;
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
sig = rb_check_to_integer(argv[0], "to_int");
|
|
|
|
if (!NIL_P(sig)) argnum = 2;
|
2008-05-29 21:08:48 +04:00
|
|
|
else sig = argv[0];
|
2007-04-19 21:37:03 +04:00
|
|
|
}
|
2012-03-15 01:10:34 +04:00
|
|
|
rb_check_arity(argc, 1, argnum);
|
2007-04-19 21:37:03 +04:00
|
|
|
if (argnum == 2) {
|
|
|
|
signo = NUM2INT(sig);
|
|
|
|
if (signo < 0 || signo > NSIG) {
|
|
|
|
rb_raise(rb_eArgError, "invalid signal number (%d)", signo);
|
|
|
|
}
|
|
|
|
if (argc > 1) {
|
|
|
|
sig = argv[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
signm = signo2signm(signo);
|
|
|
|
if (signm) {
|
|
|
|
sig = rb_sprintf("SIG%s", signm);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sig = rb_sprintf("SIG%u", signo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-03-31 06:34:43 +04:00
|
|
|
int len = sizeof(signame_prefix);
|
2007-04-19 21:37:03 +04:00
|
|
|
signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
|
2014-03-31 06:34:43 +04:00
|
|
|
if (strncmp(signm, signame_prefix, len) == 0) {
|
|
|
|
signm += len;
|
|
|
|
len = 0;
|
|
|
|
}
|
2007-04-19 21:37:03 +04:00
|
|
|
signo = signm2signo(signm);
|
|
|
|
if (!signo) {
|
2014-03-31 06:34:43 +04:00
|
|
|
rb_raise(rb_eArgError, "unsupported name `%.*s%"PRIsVALUE"'",
|
|
|
|
len, signame_prefix, sig);
|
2007-04-19 21:37:03 +04:00
|
|
|
}
|
2008-05-30 17:32:39 +04:00
|
|
|
sig = rb_sprintf("SIG%s", signm);
|
2007-04-19 21:37:03 +04:00
|
|
|
}
|
|
|
|
rb_call_super(1, &sig);
|
|
|
|
rb_iv_set(self, "signo", INT2NUM(signo));
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-05-30 17:32:39 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* signal_exception.signo -> num
|
2008-05-30 17:32:39 +04:00
|
|
|
*
|
|
|
|
* Returns a signal number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
esignal_signo(VALUE self)
|
|
|
|
{
|
|
|
|
return rb_iv_get(self, "signo");
|
|
|
|
}
|
|
|
|
|
2009-09-13 14:34:35 +04:00
|
|
|
/* :nodoc: */
|
2007-04-19 21:37:03 +04:00
|
|
|
static VALUE
|
|
|
|
interrupt_init(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE args[2];
|
|
|
|
|
|
|
|
args[0] = INT2FIX(SIGINT);
|
2007-05-29 21:13:05 +04:00
|
|
|
rb_scan_args(argc, argv, "01", &args[1]);
|
|
|
|
return rb_call_super(2, args);
|
2007-04-19 21:37:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_default_signal(int sig)
|
|
|
|
{
|
|
|
|
signal(sig, SIG_DFL);
|
|
|
|
raise(sig);
|
|
|
|
}
|
|
|
|
|
2014-05-10 20:10:32 +04:00
|
|
|
static int signal_ignored(int sig);
|
|
|
|
static void signal_enque(int sig);
|
|
|
|
|
2004-01-02 09:01:12 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* Process.kill(signal, pid, ...) -> fixnum
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2012-09-13 19:24:05 +04:00
|
|
|
* Sends the given signal to the specified process id(s) if _pid_ is positive.
|
|
|
|
* If _pid_ is zero _signal_ is sent to all processes whose group ID is equal
|
|
|
|
* to the group ID of the process. _signal_ may be an integer signal number or
|
|
|
|
* a POSIX signal name (either with or without a +SIG+ prefix). If _signal_ is
|
|
|
|
* negative (or starts with a minus sign), kills process groups instead of
|
2004-01-02 09:01:12 +03:00
|
|
|
* processes. Not all signals are available on all platforms.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-01-02 09:01:12 +03:00
|
|
|
* pid = fork do
|
|
|
|
* Signal.trap("HUP") { puts "Ouch!"; exit }
|
|
|
|
* # ... do some work ...
|
|
|
|
* end
|
|
|
|
* # ...
|
|
|
|
* Process.kill("HUP", pid)
|
|
|
|
* Process.wait
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-01-02 09:01:12 +03:00
|
|
|
* <em>produces:</em>
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-01-02 09:01:12 +03:00
|
|
|
* Ouch!
|
2009-09-13 13:51:04 +04:00
|
|
|
*
|
|
|
|
* If _signal_ is an integer but wrong for signal,
|
|
|
|
* <code>Errno::EINVAL</code> or +RangeError+ will be raised.
|
|
|
|
* Otherwise unless _signal_ is a +String+ or a +Symbol+, and a known
|
2009-11-03 20:46:28 +03:00
|
|
|
* signal name, +ArgumentError+ will be raised.
|
2009-09-13 13:51:04 +04:00
|
|
|
*
|
|
|
|
* Also, <code>Errno::ESRCH</code> or +RangeError+ for invalid _pid_,
|
|
|
|
* <code>Errno::EPERM</code> when failed because of no privilege,
|
|
|
|
* will be raised. In these cases, signals may have been sent to
|
|
|
|
* preceding processes.
|
2004-01-02 09:01:12 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_kill(int argc, VALUE *argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2013-05-12 12:41:46 +04:00
|
|
|
#ifndef HAVE_KILLPG
|
2010-12-29 04:07:26 +03:00
|
|
|
#define killpg(pg, sig) kill(-(pg), (sig))
|
2007-04-19 21:37:03 +04:00
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
int negative = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
int sig;
|
|
|
|
int i;
|
2011-05-15 17:37:47 +04:00
|
|
|
volatile VALUE str;
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
const char *s;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
rb_secure(2);
|
2012-03-15 01:10:34 +04:00
|
|
|
rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
switch (TYPE(argv[0])) {
|
|
|
|
case T_FIXNUM:
|
2000-09-19 11:54:28 +04:00
|
|
|
sig = FIX2INT(argv[0]);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
2000-03-13 10:18:45 +03:00
|
|
|
case T_SYMBOL:
|
|
|
|
s = rb_id2name(SYM2ID(argv[0]));
|
|
|
|
if (!s) rb_raise(rb_eArgError, "bad signal");
|
|
|
|
goto str_signal;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_STRING:
|
2006-08-31 14:47:44 +04:00
|
|
|
s = RSTRING_PTR(argv[0]);
|
2011-05-15 17:37:47 +04:00
|
|
|
str_signal:
|
2002-03-11 11:02:04 +03:00
|
|
|
if (s[0] == '-') {
|
|
|
|
negative++;
|
|
|
|
s++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2014-03-31 06:34:43 +04:00
|
|
|
if (strncmp(signame_prefix, s, sizeof(signame_prefix)) == 0)
|
2002-03-11 11:02:04 +03:00
|
|
|
s += 3;
|
2012-12-01 19:25:28 +04:00
|
|
|
if ((sig = signm2signo(s)) == 0)
|
2002-03-11 11:02:04 +03:00
|
|
|
rb_raise(rb_eArgError, "unsupported name `SIG%s'", s);
|
|
|
|
|
|
|
|
if (negative)
|
|
|
|
sig = -sig;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-05-15 17:37:47 +04:00
|
|
|
str = rb_check_string_type(argv[0]);
|
|
|
|
if (!NIL_P(str)) {
|
|
|
|
s = RSTRING_PTR(str);
|
|
|
|
goto str_signal;
|
2002-03-11 11:02:04 +03:00
|
|
|
}
|
2011-05-15 17:37:47 +04:00
|
|
|
rb_raise(rb_eArgError, "bad signal type %s",
|
|
|
|
rb_obj_classname(argv[0]));
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-05-10 20:10:32 +04:00
|
|
|
if (argc <= 1) return INT2FIX(0);
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
if (sig < 0) {
|
|
|
|
sig = -sig;
|
|
|
|
for (i=1; i<argc; i++) {
|
2007-04-19 21:37:03 +04:00
|
|
|
if (killpg(NUM2PIDT(argv[i]), sig) < 0)
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-05-10 20:10:32 +04:00
|
|
|
const rb_pid_t self = (GET_THREAD() == GET_VM()->main_thread) ? getpid() : -1;
|
|
|
|
int wakeup = 0;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
for (i=1; i<argc; i++) {
|
2014-05-10 20:10:32 +04:00
|
|
|
rb_pid_t pid = NUM2PIDT(argv[i]);
|
|
|
|
|
|
|
|
if ((sig != 0) && (self != -1) && (pid == self)) {
|
|
|
|
/*
|
|
|
|
* When target pid is self, many caller assume signal will be
|
|
|
|
* delivered immediately and synchronously.
|
|
|
|
*/
|
|
|
|
switch (sig) {
|
|
|
|
case SIGSEGV:
|
|
|
|
#ifdef SIGBUS
|
|
|
|
case SIGBUS:
|
|
|
|
#endif
|
|
|
|
ruby_kill(pid, sig);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (signal_ignored(sig)) break;
|
|
|
|
signal_enque(sig);
|
|
|
|
wakeup = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (kill(pid, sig) < 0) {
|
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wakeup) {
|
|
|
|
rb_threadptr_check_signal(GET_VM()->main_thread);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2013-03-19 08:40:22 +04:00
|
|
|
rb_thread_execute_interrupts(rb_thread_current());
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
return INT2FIX(i-1);
|
|
|
|
}
|
|
|
|
|
2008-10-24 22:58:52 +04:00
|
|
|
static struct {
|
2008-09-04 08:22:04 +04:00
|
|
|
rb_atomic_t cnt[RUBY_NSIG];
|
|
|
|
rb_atomic_t size;
|
|
|
|
} signal_buff;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-08-16 11:23:04 +04:00
|
|
|
#ifdef __dietlibc__
|
|
|
|
#define sighandler_t sh_t
|
2013-10-06 17:52:39 +04:00
|
|
|
#else
|
|
|
|
#define sighandler_t ruby_sighandler_t
|
2002-08-16 11:23:04 +04:00
|
|
|
#endif
|
|
|
|
|
2005-09-14 12:30:16 +04:00
|
|
|
typedef RETSIGTYPE (*sighandler_t)(int);
|
2010-01-25 06:11:46 +03:00
|
|
|
#ifdef USE_SIGALTSTACK
|
2008-11-27 10:12:35 +03:00
|
|
|
typedef void ruby_sigaction_t(int, siginfo_t*, void*);
|
|
|
|
#define SIGINFO_ARG , siginfo_t *info, void *ctx
|
|
|
|
#else
|
|
|
|
typedef RETSIGTYPE ruby_sigaction_t(int);
|
|
|
|
#define SIGINFO_ARG
|
|
|
|
#endif
|
2002-01-21 10:44:06 +03:00
|
|
|
|
2008-11-21 21:27:33 +03:00
|
|
|
#ifdef USE_SIGALTSTACK
|
2013-09-12 09:37:04 +04:00
|
|
|
int
|
|
|
|
rb_sigaltstack_size(void)
|
2012-12-15 18:20:12 +04:00
|
|
|
{
|
|
|
|
/* XXX: BSD_vfprintf() uses >1500KiB stack and x86-64 need >5KiB stack. */
|
|
|
|
int size = 8192;
|
|
|
|
|
|
|
|
#ifdef MINSIGSTKSZ
|
|
|
|
if (size < MINSIGSTKSZ)
|
|
|
|
size = MINSIGSTKSZ;
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
|
|
|
|
{
|
|
|
|
int pagesize;
|
2012-12-15 21:10:50 +04:00
|
|
|
pagesize = (int)sysconf(_SC_PAGE_SIZE);
|
2012-12-15 18:20:12 +04:00
|
|
|
if (size < pagesize)
|
|
|
|
size = pagesize;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2008-11-21 21:27:33 +03:00
|
|
|
/* alternate stack for SIGSEGV */
|
2010-05-13 20:20:26 +04:00
|
|
|
void
|
|
|
|
rb_register_sigaltstack(rb_thread_t *th)
|
2008-11-24 17:25:45 +03:00
|
|
|
{
|
2008-11-21 21:27:33 +03:00
|
|
|
stack_t newSS, oldSS;
|
|
|
|
|
2011-07-30 05:57:06 +04:00
|
|
|
if (!th->altstack)
|
|
|
|
rb_bug("rb_register_sigaltstack: th->altstack not initialized\n");
|
2008-11-21 21:27:33 +03:00
|
|
|
|
2011-07-30 05:57:06 +04:00
|
|
|
newSS.ss_sp = th->altstack;
|
2012-12-15 18:20:12 +04:00
|
|
|
newSS.ss_size = rb_sigaltstack_size();
|
2008-11-21 21:27:33 +03:00
|
|
|
newSS.ss_flags = 0;
|
|
|
|
|
2009-02-06 14:40:33 +03:00
|
|
|
sigaltstack(&newSS, &oldSS); /* ignore error. */
|
2008-11-21 21:27:33 +03:00
|
|
|
}
|
2011-07-30 05:57:06 +04:00
|
|
|
#endif /* USE_SIGALTSTACK */
|
2008-11-21 21:27:33 +03:00
|
|
|
|
2012-05-17 06:48:59 +04:00
|
|
|
#ifdef POSIX_SIGNAL
|
2002-01-21 10:44:06 +03:00
|
|
|
static sighandler_t
|
2005-11-08 11:49:45 +03:00
|
|
|
ruby_signal(int signum, sighandler_t handler)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-01-21 10:44:06 +03:00
|
|
|
struct sigaction sigact, old;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-04-26 12:30:22 +04:00
|
|
|
#if 0
|
2005-02-21 12:33:34 +03:00
|
|
|
rb_trap_accept_nativethreads[signum] = 0;
|
2008-04-26 12:30:22 +04:00
|
|
|
#endif
|
2005-02-21 12:33:34 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
sigemptyset(&sigact.sa_mask);
|
2010-11-11 15:30:35 +03:00
|
|
|
#ifdef USE_SIGALTSTACK
|
2008-11-27 10:12:35 +03:00
|
|
|
sigact.sa_sigaction = (ruby_sigaction_t*)handler;
|
2007-11-30 17:49:45 +03:00
|
|
|
sigact.sa_flags = SA_SIGINFO;
|
|
|
|
#else
|
|
|
|
sigact.sa_handler = handler;
|
1998-01-16 15:13:05 +03:00
|
|
|
sigact.sa_flags = 0;
|
2007-11-30 17:49:45 +03:00
|
|
|
#endif
|
|
|
|
|
2014-05-09 18:31:27 +04:00
|
|
|
switch (signum) {
|
1999-10-12 08:53:36 +04:00
|
|
|
#ifdef SA_NOCLDWAIT
|
2014-05-09 18:31:27 +04:00
|
|
|
case SIGCHLD:
|
|
|
|
if (handler == SIG_IGN)
|
|
|
|
sigact.sa_flags |= SA_NOCLDWAIT;
|
|
|
|
break;
|
1999-10-12 08:53:36 +04:00
|
|
|
#endif
|
2008-11-21 21:27:33 +03:00
|
|
|
#if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
|
2014-05-09 18:31:27 +04:00
|
|
|
case SIGSEGV:
|
2012-08-23 06:59:24 +04:00
|
|
|
#ifdef SIGBUS
|
2014-05-09 18:31:27 +04:00
|
|
|
case SIGBUS:
|
2012-08-23 06:59:24 +04:00
|
|
|
#endif
|
2008-11-27 10:32:56 +03:00
|
|
|
sigact.sa_flags |= SA_ONSTACK;
|
2014-05-09 18:31:27 +04:00
|
|
|
break;
|
2008-11-21 21:27:33 +03:00
|
|
|
#endif
|
2014-05-09 18:31:27 +04:00
|
|
|
}
|
2013-07-14 21:43:55 +04:00
|
|
|
(void)VALGRIND_MAKE_MEM_DEFINED(&old, sizeof(old));
|
2008-12-04 07:57:58 +03:00
|
|
|
if (sigaction(signum, &sigact, &old) < 0) {
|
|
|
|
if (errno != 0 && errno != EINVAL) {
|
2009-11-24 14:03:51 +03:00
|
|
|
rb_bug_errno("sigaction", errno);
|
2008-12-04 07:57:58 +03:00
|
|
|
}
|
|
|
|
}
|
2002-01-21 10:44:06 +03:00
|
|
|
return old.sa_handler;
|
|
|
|
}
|
|
|
|
|
2007-11-30 17:49:45 +03:00
|
|
|
sighandler_t
|
2005-11-08 11:49:45 +03:00
|
|
|
posix_signal(int signum, sighandler_t handler)
|
2002-01-21 10:44:06 +03:00
|
|
|
{
|
2007-12-08 12:01:43 +03:00
|
|
|
return ruby_signal(signum, handler);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2005-02-21 12:33:34 +03:00
|
|
|
|
|
|
|
#else /* !POSIX_SIGNAL */
|
2010-12-29 04:07:26 +03:00
|
|
|
#define ruby_signal(sig,handler) (/* rb_trap_accept_nativethreads[(sig)] = 0,*/ signal((sig),(handler)))
|
2008-04-26 12:30:22 +04:00
|
|
|
#if 0 /* def HAVE_NATIVETHREAD */
|
2005-02-22 17:50:33 +03:00
|
|
|
static sighandler_t
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ruby_nativethread_signal(int signum, sighandler_t handler)
|
2005-02-22 17:50:33 +03:00
|
|
|
{
|
|
|
|
sighandler_t old;
|
|
|
|
|
|
|
|
old = signal(signum, handler);
|
|
|
|
rb_trap_accept_nativethreads[signum] = 1;
|
|
|
|
return old;
|
|
|
|
}
|
2005-02-21 12:33:34 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
2014-05-10 20:10:32 +04:00
|
|
|
static int
|
|
|
|
signal_ignored(int sig)
|
|
|
|
{
|
|
|
|
#ifdef POSIX_SIGNAL
|
|
|
|
struct sigaction old;
|
|
|
|
(void)VALGRIND_MAKE_MEM_DEFINED(&old, sizeof(old));
|
|
|
|
if (sigaction(sig, NULL, &old) < 0) return FALSE;
|
|
|
|
return old.sa_handler == SIG_IGN;
|
|
|
|
#else
|
|
|
|
sighandler_t old = signal(sig, SIG_DFL);
|
|
|
|
signal(sig, old);
|
|
|
|
return old == SIG_IGN;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
signal_enque(int sig)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2008-09-04 08:22:04 +04:00
|
|
|
ATOMIC_INC(signal_buff.cnt[sig]);
|
|
|
|
ATOMIC_INC(signal_buff.size);
|
2014-05-10 20:10:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static RETSIGTYPE
|
|
|
|
sighandler(int sig)
|
|
|
|
{
|
|
|
|
signal_enque(sig);
|
2011-06-27 04:30:41 +04:00
|
|
|
rb_thread_wakeup_timer_thread();
|
2007-02-23 09:59:12 +03:00
|
|
|
#if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
|
|
|
|
ruby_signal(sig, sighandler);
|
|
|
|
#endif
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2009-01-02 00:50:01 +03:00
|
|
|
int
|
* cont.c (rb_fiber_current), dln.c (dln_print_undef, dln_undefined),
eval.c (rb_iterator_p, rb_need_block), load.c: (Init_load), ruby.c
(uscore_get, rb_f_chop), st.c (stat_col), signal.c
(rb_signal_buff_size, ruby_sig_finalize), thread.c
(rb_thread_sleep_forever, rb_thread_sleep_deadly, rb_thread_alone):
protoized.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-01 15:51:44 +03:00
|
|
|
rb_signal_buff_size(void)
|
2009-01-02 00:50:01 +03:00
|
|
|
{
|
|
|
|
return signal_buff.size;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#if HAVE_PTHREAD_H
|
|
|
|
#include <pthread.h>
|
2005-09-25 03:11:11 +04:00
|
|
|
#endif
|
2005-03-02 11:11:28 +03:00
|
|
|
|
2011-07-10 21:04:40 +04:00
|
|
|
static void
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_disable_interrupt(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-11-19 14:35:34 +04:00
|
|
|
#ifdef HAVE_PTHREAD_SIGMASK
|
2006-12-31 18:02:22 +03:00
|
|
|
sigset_t mask;
|
|
|
|
sigfillset(&mask);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &mask, NULL);
|
2005-02-21 12:33:34 +03:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2005-02-21 12:33:34 +03:00
|
|
|
|
2011-07-10 21:04:40 +04:00
|
|
|
static void
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_enable_interrupt(void)
|
|
|
|
{
|
2012-11-19 14:35:34 +04:00
|
|
|
#ifdef HAVE_PTHREAD_SIGMASK
|
2006-12-31 18:02:22 +03:00
|
|
|
sigset_t mask;
|
|
|
|
sigemptyset(&mask);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &mask, NULL);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
int
|
2008-09-04 08:22:04 +04:00
|
|
|
rb_get_next_signal(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int i, sig = 0;
|
|
|
|
|
2011-07-01 02:29:34 +04:00
|
|
|
if (signal_buff.size != 0) {
|
|
|
|
for (i=1; i<RUBY_NSIG; i++) {
|
|
|
|
if (signal_buff.cnt[i] > 0) {
|
2012-11-19 14:54:55 +04:00
|
|
|
ATOMIC_DEC(signal_buff.cnt[i]);
|
|
|
|
ATOMIC_DEC(signal_buff.size);
|
2011-07-01 02:29:34 +04:00
|
|
|
sig = i;
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
return sig;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2013-02-21 11:34:53 +04:00
|
|
|
|
2013-11-21 10:33:41 +04:00
|
|
|
#if defined(USE_SIGALTSTACK) || defined(_WIN32)
|
2014-04-04 12:37:25 +04:00
|
|
|
NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
|
2014-04-10 03:16:10 +04:00
|
|
|
#if defined(HAVE_UCONTEXT_H) && defined __linux__ && (defined __i386__ || defined __x86_64__)
|
2014-04-04 12:37:25 +04:00
|
|
|
static void
|
|
|
|
check_stack_overflow(const uintptr_t addr, const ucontext_t *ctx)
|
|
|
|
{
|
|
|
|
# if defined REG_RSP
|
|
|
|
const greg_t sp = ctx->uc_mcontext.gregs[REG_RSP];
|
|
|
|
# else
|
|
|
|
const greg_t sp = ctx->uc_mcontext.gregs[REG_ESP];
|
|
|
|
# endif
|
|
|
|
enum {pagesize = 4096};
|
|
|
|
if ((uintptr_t)sp / pagesize == addr / pagesize) {
|
|
|
|
ruby_thread_stack_overflow(GET_THREAD());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2013-02-21 11:34:53 +04:00
|
|
|
static void
|
|
|
|
check_stack_overflow(const void *addr)
|
|
|
|
{
|
|
|
|
int ruby_stack_overflowed_p(const rb_thread_t *, const void *);
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
if (ruby_stack_overflowed_p(th, addr)) {
|
|
|
|
ruby_thread_stack_overflow(th);
|
|
|
|
}
|
|
|
|
}
|
2014-04-04 12:37:25 +04:00
|
|
|
#endif
|
2013-11-21 10:33:41 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define CHECK_STACK_OVERFLOW() check_stack_overflow(0)
|
|
|
|
#else
|
2013-12-03 07:18:49 +04:00
|
|
|
#define FAULT_ADDRESS info->si_addr
|
2014-04-10 03:16:10 +04:00
|
|
|
#if defined(HAVE_UCONTEXT_H) && defined __linux__ && (defined __i386__ || defined __x86_64__)
|
2014-04-04 12:37:25 +04:00
|
|
|
# define CHECK_STACK_OVERFLOW() check_stack_overflow((uintptr_t)FAULT_ADDRESS, ctx)
|
|
|
|
#else
|
|
|
|
# define CHECK_STACK_OVERFLOW() check_stack_overflow(FAULT_ADDRESS)
|
|
|
|
#endif
|
2013-12-03 07:18:49 +04:00
|
|
|
#define MESSAGE_FAULT_ADDRESS " at %p", FAULT_ADDRESS
|
2013-11-21 10:33:41 +04:00
|
|
|
#endif
|
2013-02-21 11:34:53 +04:00
|
|
|
#else
|
|
|
|
#define CHECK_STACK_OVERFLOW() (void)0
|
|
|
|
#endif
|
2013-12-03 07:18:49 +04:00
|
|
|
#ifndef MESSAGE_FAULT_ADDRESS
|
|
|
|
#define MESSAGE_FAULT_ADDRESS
|
|
|
|
#endif
|
2013-02-21 11:34:53 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef SIGBUS
|
|
|
|
static RETSIGTYPE
|
2011-07-02 23:59:05 +04:00
|
|
|
sigbus(int sig SIGINFO_ARG)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2011-07-02 23:59:05 +04:00
|
|
|
/*
|
|
|
|
* Mac OS X makes KERN_PROTECTION_FAILURE when thread touch guard page.
|
2013-04-09 04:24:24 +04:00
|
|
|
* and it's delivered as SIGBUS instead of SIGSEGV to userland. It's crazy
|
2011-07-02 23:59:05 +04:00
|
|
|
* wrong IMHO. but anyway we have to care it. Sigh.
|
|
|
|
*/
|
2013-02-21 11:34:53 +04:00
|
|
|
#if defined __APPLE__
|
|
|
|
CHECK_STACK_OVERFLOW();
|
2011-07-02 23:59:05 +04:00
|
|
|
#endif
|
2013-12-03 07:18:49 +04:00
|
|
|
rb_bug("Bus Error" MESSAGE_FAULT_ADDRESS);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGSEGV
|
2013-09-12 09:37:04 +04:00
|
|
|
static void
|
|
|
|
ruby_abort(void)
|
2013-02-21 09:18:38 +04:00
|
|
|
{
|
|
|
|
#ifdef __sun
|
|
|
|
/* Solaris's abort() is async signal unsafe. Of course, it is not
|
|
|
|
* POSIX compliant.
|
|
|
|
*/
|
2013-02-22 10:02:54 +04:00
|
|
|
raise(SIGABRT);
|
2013-02-21 09:18:38 +04:00
|
|
|
#else
|
|
|
|
abort();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int segv_received = 0;
|
2013-02-21 09:18:38 +04:00
|
|
|
extern int ruby_disable_gc_stress;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static RETSIGTYPE
|
2008-11-27 09:05:07 +03:00
|
|
|
sigsegv(int sig SIGINFO_ARG)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2013-02-21 09:18:38 +04:00
|
|
|
if (segv_received) {
|
2013-02-24 05:16:46 +04:00
|
|
|
ssize_t RB_UNUSED_VAR(err);
|
2014-01-27 17:09:26 +04:00
|
|
|
static const char msg[] = "SEGV received in SEGV handler\n";
|
2013-02-24 04:17:29 +04:00
|
|
|
|
|
|
|
err = write(2, msg, sizeof(msg));
|
2013-02-21 09:18:38 +04:00
|
|
|
ruby_abort();
|
|
|
|
}
|
|
|
|
|
2013-02-21 11:34:53 +04:00
|
|
|
CHECK_STACK_OVERFLOW();
|
2013-02-21 09:18:38 +04:00
|
|
|
|
|
|
|
segv_received = 1;
|
|
|
|
ruby_disable_gc_stress = 1;
|
2013-12-03 07:18:49 +04:00
|
|
|
rb_bug("Segmentation fault" MESSAGE_FAULT_ADDRESS);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-29 21:08:37 +04:00
|
|
|
static void
|
2008-09-04 08:22:04 +04:00
|
|
|
signal_exec(VALUE cmd, int safe, int sig)
|
2007-05-29 21:08:37 +04:00
|
|
|
{
|
2012-11-26 12:05:49 +04:00
|
|
|
rb_thread_t *cur_th = GET_THREAD();
|
2012-11-26 14:57:39 +04:00
|
|
|
volatile unsigned long old_interrupt_mask = cur_th->interrupt_mask;
|
2012-11-26 12:05:49 +04:00
|
|
|
int state;
|
|
|
|
|
2012-11-26 16:17:10 +04:00
|
|
|
cur_th->interrupt_mask |= TRAP_INTERRUPT_MASK;
|
2012-11-26 12:05:49 +04:00
|
|
|
TH_PUSH_TAG(cur_th);
|
|
|
|
if ((state = EXEC_TAG()) == 0) {
|
2012-11-26 13:25:47 +04:00
|
|
|
VALUE signum = INT2NUM(sig);
|
2012-11-26 12:05:49 +04:00
|
|
|
rb_eval_cmd(cmd, rb_ary_new3(1, signum), safe);
|
|
|
|
}
|
|
|
|
TH_POP_TAG();
|
2012-11-26 13:28:35 +04:00
|
|
|
cur_th = GET_THREAD();
|
2012-11-26 14:57:39 +04:00
|
|
|
cur_th->interrupt_mask = old_interrupt_mask;
|
2012-11-26 12:05:49 +04:00
|
|
|
|
|
|
|
if (state) {
|
2012-12-23 14:18:58 +04:00
|
|
|
/* XXX: should be replaced with rb_threadptr_pending_interrupt_enque() */
|
2012-11-26 12:05:49 +04:00
|
|
|
JUMP_TAG(state);
|
|
|
|
}
|
2007-05-29 21:08:37 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_trap_exit(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-09-04 08:22:04 +04:00
|
|
|
rb_vm_t *vm = GET_VM();
|
|
|
|
VALUE trap_exit = vm->trap_list[0].cmd;
|
2000-11-27 12:23:38 +03:00
|
|
|
|
2008-09-04 08:22:04 +04:00
|
|
|
if (trap_exit) {
|
|
|
|
vm->trap_list[0].cmd = 0;
|
|
|
|
signal_exec(trap_exit, vm->trap_list[0].safe, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 09:37:46 +03:00
|
|
|
rb_signal_exec(rb_thread_t *th, int sig)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-09-04 08:22:04 +04:00
|
|
|
rb_vm_t *vm = GET_VM();
|
|
|
|
VALUE cmd = vm->trap_list[sig].cmd;
|
|
|
|
int safe = vm->trap_list[sig].safe;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
if (cmd == 0) {
|
|
|
|
switch (sig) {
|
|
|
|
case SIGINT:
|
|
|
|
rb_interrupt();
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
#ifdef SIGHUP
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
case SIGHUP:
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
case SIGQUIT:
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
2007-04-19 21:37:03 +04:00
|
|
|
#ifdef SIGTERM
|
|
|
|
case SIGTERM:
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
#ifdef SIGALRM
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
case SIGALRM:
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
case SIGUSR1:
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
case SIGUSR2:
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
2009-06-08 20:14:06 +04:00
|
|
|
rb_threadptr_signal_raise(th, sig);
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmd == Qundef) {
|
2009-06-08 20:14:06 +04:00
|
|
|
rb_threadptr_signal_exit(th);
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 08:22:04 +04:00
|
|
|
signal_exec(cmd, safe, sig);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-15 17:38:32 +04:00
|
|
|
static sighandler_t
|
|
|
|
default_handler(int sig)
|
|
|
|
{
|
|
|
|
sighandler_t func;
|
|
|
|
switch (sig) {
|
|
|
|
case SIGINT:
|
|
|
|
#ifdef SIGHUP
|
|
|
|
case SIGHUP:
|
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
|
|
|
case SIGQUIT:
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
|
|
|
case SIGTERM:
|
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
|
|
|
case SIGALRM:
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
|
|
|
case SIGUSR1:
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
|
|
|
case SIGUSR2:
|
|
|
|
#endif
|
|
|
|
func = sighandler;
|
|
|
|
break;
|
|
|
|
#ifdef SIGBUS
|
|
|
|
case SIGBUS:
|
2011-07-02 23:59:05 +04:00
|
|
|
func = (sighandler_t)sigbus;
|
2007-06-15 17:38:32 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
|
|
|
case SIGSEGV:
|
2008-11-27 09:05:07 +03:00
|
|
|
func = (sighandler_t)sigsegv;
|
2007-06-15 17:38:32 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
|
|
|
case SIGPIPE:
|
2011-05-28 11:11:54 +04:00
|
|
|
func = SIG_IGN;
|
2007-06-15 17:38:32 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
func = SIG_DFL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2007-05-29 21:08:37 +04:00
|
|
|
static sighandler_t
|
2007-06-15 17:38:32 +04:00
|
|
|
trap_handler(VALUE *cmd, int sig)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-07-16 13:04:37 +04:00
|
|
|
sighandler_t func = sighandler;
|
2007-05-29 21:08:37 +04:00
|
|
|
VALUE command;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-05-29 21:08:37 +04:00
|
|
|
if (NIL_P(*cmd)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
func = SIG_IGN;
|
|
|
|
}
|
2005-06-30 10:20:09 +04:00
|
|
|
else {
|
2007-05-29 21:08:37 +04:00
|
|
|
command = rb_check_string_type(*cmd);
|
2009-01-23 07:25:29 +03:00
|
|
|
if (NIL_P(command) && SYMBOL_P(*cmd)) {
|
|
|
|
command = rb_id2str(SYM2ID(*cmd));
|
|
|
|
if (!command) rb_raise(rb_eArgError, "bad handler");
|
|
|
|
}
|
2005-06-30 10:20:09 +04:00
|
|
|
if (!NIL_P(command)) {
|
|
|
|
SafeStringValue(command); /* taint check */
|
2008-07-16 13:04:37 +04:00
|
|
|
*cmd = command;
|
2006-08-31 14:47:44 +04:00
|
|
|
switch (RSTRING_LEN(command)) {
|
2005-06-30 10:20:09 +04:00
|
|
|
case 0:
|
2007-06-15 17:38:32 +04:00
|
|
|
goto sig_ign;
|
2005-06-30 10:20:09 +04:00
|
|
|
break;
|
2007-06-15 17:38:32 +04:00
|
|
|
case 14:
|
|
|
|
if (strncmp(RSTRING_PTR(command), "SYSTEM_DEFAULT", 14) == 0) {
|
|
|
|
func = SIG_DFL;
|
|
|
|
*cmd = 0;
|
|
|
|
}
|
|
|
|
break;
|
2005-06-30 10:20:09 +04:00
|
|
|
case 7:
|
2006-08-31 14:47:44 +04:00
|
|
|
if (strncmp(RSTRING_PTR(command), "SIG_IGN", 7) == 0) {
|
2007-06-15 17:38:32 +04:00
|
|
|
sig_ign:
|
|
|
|
func = SIG_IGN;
|
|
|
|
*cmd = 0;
|
2005-06-30 10:20:09 +04:00
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
else if (strncmp(RSTRING_PTR(command), "SIG_DFL", 7) == 0) {
|
2007-06-15 17:38:32 +04:00
|
|
|
sig_dfl:
|
|
|
|
func = default_handler(sig);
|
|
|
|
*cmd = 0;
|
2005-06-30 10:20:09 +04:00
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
else if (strncmp(RSTRING_PTR(command), "DEFAULT", 7) == 0) {
|
2007-06-15 17:38:32 +04:00
|
|
|
goto sig_dfl;
|
2005-06-30 10:20:09 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
2006-08-31 14:47:44 +04:00
|
|
|
if (strncmp(RSTRING_PTR(command), "IGNORE", 6) == 0) {
|
2007-06-15 17:38:32 +04:00
|
|
|
goto sig_ign;
|
2005-06-30 10:20:09 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2006-08-31 14:47:44 +04:00
|
|
|
if (strncmp(RSTRING_PTR(command), "EXIT", 4) == 0) {
|
2007-05-29 21:08:37 +04:00
|
|
|
*cmd = Qundef;
|
2005-06-30 10:20:09 +04:00
|
|
|
}
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2007-05-29 21:08:37 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_proc_t *proc;
|
|
|
|
GetProcPtr(*cmd, proc);
|
* bignum.c (big_rshift), compile.c (validate_label,
iseq_build_from_ary_exception), cont.c (cont_capture), dir.c
(dir_open_dir), gc.c (objspace_each_objects), io.c (pipe_open)
(rb_io_advise), parse.y (parser_compile_string)
(rb_parser_compile_file), proc.c (binding_free), process.c
(rb_proc_exec_n, rb_seteuid_core, proc_setegid, rb_setegid_core)
(p_uid_exchange, p_gid_exchange), regparse.c (strdup_with_null),
signal.c (sig_dfl), vm.c (rb_iseq_eval, rb_iseq_eval_main),
vm_insnhelper.c (vm_expandarray): suppress
unused-but-set-variable warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-05 13:57:00 +04:00
|
|
|
(void)proc;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-29 21:08:37 +04:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
trap_signm(VALUE vsig)
|
|
|
|
{
|
|
|
|
int sig = -1;
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
switch (TYPE(vsig)) {
|
2000-04-10 09:48:43 +04:00
|
|
|
case T_FIXNUM:
|
2007-05-29 21:08:37 +04:00
|
|
|
sig = FIX2INT(vsig);
|
|
|
|
if (sig < 0 || sig >= NSIG) {
|
|
|
|
rb_raise(rb_eArgError, "invalid signal number (%d)", sig);
|
|
|
|
}
|
2000-04-10 09:48:43 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_SYMBOL:
|
2007-05-29 21:08:37 +04:00
|
|
|
s = rb_id2name(SYM2ID(vsig));
|
2000-04-10 09:48:43 +04:00
|
|
|
if (!s) rb_raise(rb_eArgError, "bad signal");
|
|
|
|
goto str_signal;
|
|
|
|
|
2007-05-29 21:08:37 +04:00
|
|
|
default:
|
|
|
|
s = StringValuePtr(vsig);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-04-10 09:48:43 +04:00
|
|
|
str_signal:
|
2014-03-31 06:34:43 +04:00
|
|
|
if (strncmp(signame_prefix, s, sizeof(signame_prefix)) == 0)
|
1998-01-16 15:13:05 +03:00
|
|
|
s += 3;
|
|
|
|
sig = signm2signo(s);
|
|
|
|
if (sig == 0 && strcmp(s, "EXIT") != 0)
|
2002-03-08 10:03:09 +03:00
|
|
|
rb_raise(rb_eArgError, "unsupported signal SIG%s", s);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2007-05-29 21:08:37 +04:00
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2012-11-19 14:35:34 +04:00
|
|
|
trap(int sig, sighandler_t func, VALUE command)
|
2007-05-29 21:08:37 +04:00
|
|
|
{
|
2012-11-19 14:35:34 +04:00
|
|
|
sighandler_t oldfunc;
|
|
|
|
VALUE oldcmd;
|
2008-09-04 08:22:04 +04:00
|
|
|
rb_vm_t *vm = GET_VM();
|
2007-05-29 21:08:37 +04:00
|
|
|
|
2012-11-19 14:35:34 +04:00
|
|
|
/*
|
|
|
|
* Be careful. ruby_signal() and trap_list[sig].cmd must be changed
|
|
|
|
* atomically. In current implementation, we only need to don't call
|
|
|
|
* RUBY_VM_CHECK_INTS().
|
|
|
|
*/
|
2003-03-25 18:25:18 +03:00
|
|
|
oldfunc = ruby_signal(sig, func);
|
2008-09-04 08:22:04 +04:00
|
|
|
oldcmd = vm->trap_list[sig].cmd;
|
2007-05-29 21:08:37 +04:00
|
|
|
switch (oldcmd) {
|
|
|
|
case 0:
|
2003-03-25 18:25:18 +03:00
|
|
|
if (oldfunc == SIG_IGN) oldcmd = rb_str_new2("IGNORE");
|
2014-05-10 03:48:47 +04:00
|
|
|
else if (oldfunc == SIG_DFL) oldcmd = rb_str_new2("SYSTEM_DEFAULT");
|
2003-03-25 18:25:18 +03:00
|
|
|
else if (oldfunc == sighandler) oldcmd = rb_str_new2("DEFAULT");
|
|
|
|
else oldcmd = Qnil;
|
2007-05-29 21:08:37 +04:00
|
|
|
break;
|
|
|
|
case Qundef:
|
|
|
|
oldcmd = rb_str_new2("EXIT");
|
|
|
|
break;
|
2003-03-25 18:25:18 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-04 08:22:04 +04:00
|
|
|
vm->trap_list[sig].cmd = command;
|
|
|
|
vm->trap_list[sig].safe = rb_safe_level();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-11-19 14:35:34 +04:00
|
|
|
return oldcmd;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2011-12-05 09:33:49 +04:00
|
|
|
static int
|
|
|
|
reserved_signal_p(int signo)
|
2011-07-12 08:55:50 +04:00
|
|
|
{
|
|
|
|
/* Synchronous signal can't deliver to main thread */
|
|
|
|
#ifdef SIGSEGV
|
|
|
|
if (signo == SIGSEGV)
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
|
|
|
if (signo == SIGBUS)
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
|
|
|
if (signo == SIGILL)
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
|
|
|
if (signo == SIGFPE)
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* used ubf internal see thread_pthread.c. */
|
|
|
|
#ifdef SIGVTALRM
|
|
|
|
if (signo == SIGVTALRM)
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-27 19:07:43 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* Signal.trap( signal, command ) -> obj
|
|
|
|
* Signal.trap( signal ) {| | block } -> obj
|
2003-12-27 19:07:43 +03:00
|
|
|
*
|
|
|
|
* Specifies the handling of signals. The first parameter is a signal
|
|
|
|
* name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a
|
|
|
|
* signal number. The characters ``SIG'' may be omitted from the
|
|
|
|
* signal name. The command or block specifies code to be run when the
|
2007-06-15 18:33:59 +04:00
|
|
|
* signal is raised.
|
|
|
|
* If the command is the string ``IGNORE'' or ``SIG_IGN'', the signal
|
|
|
|
* will be ignored.
|
|
|
|
* If the command is ``DEFAULT'' or ``SIG_DFL'', the Ruby's default handler
|
|
|
|
* will be invoked.
|
|
|
|
* If the command is ``EXIT'', the script will be terminated by the signal.
|
2007-06-15 17:38:32 +04:00
|
|
|
* If the command is ``SYSTEM_DEFAULT'', the operating system's default
|
|
|
|
* handler will be invoked.
|
2007-06-15 18:33:59 +04:00
|
|
|
* Otherwise, the given command or block will be run.
|
2003-12-27 19:07:43 +03:00
|
|
|
* The special signal name ``EXIT'' or signal number zero will be
|
|
|
|
* invoked just prior to program termination.
|
|
|
|
* trap returns the previous handler for the given signal.
|
|
|
|
*
|
|
|
|
* Signal.trap(0, proc { puts "Terminating: #{$$}" })
|
|
|
|
* Signal.trap("CLD") { puts "Child died" }
|
|
|
|
* fork && Process.wait
|
|
|
|
*
|
|
|
|
* produces:
|
|
|
|
* Terminating: 27461
|
|
|
|
* Child died
|
|
|
|
* Terminating: 27460
|
|
|
|
*/
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
sig_trap(int argc, VALUE *argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-11-19 14:35:34 +04:00
|
|
|
int sig;
|
|
|
|
sighandler_t func;
|
|
|
|
VALUE cmd;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
rb_secure(2);
|
2012-03-15 01:10:34 +04:00
|
|
|
rb_check_arity(argc, 1, 2);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-11-19 14:35:34 +04:00
|
|
|
sig = trap_signm(argv[0]);
|
|
|
|
if (reserved_signal_p(sig)) {
|
|
|
|
const char *name = signo2signm(sig);
|
2012-02-23 14:57:55 +04:00
|
|
|
if (name)
|
|
|
|
rb_raise(rb_eArgError, "can't trap reserved signal: SIG%s", name);
|
|
|
|
else
|
2012-11-19 14:35:34 +04:00
|
|
|
rb_raise(rb_eArgError, "can't trap reserved signal: %d", sig);
|
2011-07-12 08:55:50 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
if (argc == 1) {
|
2012-11-19 14:35:34 +04:00
|
|
|
cmd = rb_block_proc();
|
|
|
|
func = sighandler;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2009-03-10 22:22:11 +03:00
|
|
|
else {
|
2012-11-19 14:35:34 +04:00
|
|
|
cmd = argv[1];
|
|
|
|
func = trap_handler(&cmd, sig);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-11-19 14:35:34 +04:00
|
|
|
if (OBJ_TAINTED(cmd)) {
|
2001-11-13 11:19:52 +03:00
|
|
|
rb_raise(rb_eSecurityError, "Insecure: tainted signal trap");
|
|
|
|
}
|
2011-05-15 15:55:52 +04:00
|
|
|
|
2012-11-19 14:35:34 +04:00
|
|
|
return trap(sig, func, cmd);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 19:07:43 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* Signal.list -> a_hash
|
2003-12-27 19:07:43 +03:00
|
|
|
*
|
|
|
|
* Returns a list of signal names mapped to the corresponding
|
|
|
|
* underlying signal numbers.
|
|
|
|
*
|
2008-06-11 03:23:36 +04:00
|
|
|
* Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
|
2003-12-27 19:07:43 +03:00
|
|
|
*/
|
2001-08-23 10:02:15 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
sig_list(void)
|
2001-08-23 10:02:15 +04:00
|
|
|
{
|
|
|
|
VALUE h = rb_hash_new();
|
2008-04-26 12:30:22 +04:00
|
|
|
const struct signals *sigs;
|
2001-08-23 10:02:15 +04:00
|
|
|
|
|
|
|
for (sigs = siglist; sigs->signm; sigs++) {
|
|
|
|
rb_hash_aset(h, rb_str_new2(sigs->signm), INT2FIX(sigs->signo));
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2002-01-21 10:44:06 +03:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
install_sighandler(int signum, sighandler_t handler)
|
2002-01-21 10:44:06 +03:00
|
|
|
{
|
|
|
|
sighandler_t old;
|
|
|
|
|
2012-11-19 14:38:02 +04:00
|
|
|
/* At this time, there is no subthread. Then sigmask guarantee atomics. */
|
2011-07-12 09:08:28 +04:00
|
|
|
rb_disable_interrupt();
|
2002-01-21 10:44:06 +03:00
|
|
|
old = ruby_signal(signum, handler);
|
2012-11-19 14:38:02 +04:00
|
|
|
/* signal handler should be inherited during exec. */
|
2002-01-21 10:44:06 +03:00
|
|
|
if (old != SIG_DFL) {
|
|
|
|
ruby_signal(signum, old);
|
|
|
|
}
|
2011-07-12 09:08:28 +04:00
|
|
|
rb_enable_interrupt();
|
2002-01-21 10:44:06 +03:00
|
|
|
}
|
|
|
|
|
2008-04-26 13:36:35 +04:00
|
|
|
#if defined(SIGCLD) || defined(SIGCHLD)
|
2003-11-05 17:00:11 +03:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
init_sigchld(int sig)
|
2003-11-05 17:00:11 +03:00
|
|
|
{
|
|
|
|
sighandler_t oldfunc;
|
|
|
|
|
2011-07-12 09:12:29 +04:00
|
|
|
rb_disable_interrupt();
|
2003-11-05 17:00:11 +03:00
|
|
|
oldfunc = ruby_signal(sig, SIG_DFL);
|
|
|
|
if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
|
|
|
|
ruby_signal(sig, oldfunc);
|
2014-02-27 11:10:14 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 08:22:04 +04:00
|
|
|
GET_VM()->trap_list[sig].cmd = 0;
|
2003-11-05 17:00:11 +03:00
|
|
|
}
|
2011-07-12 09:12:29 +04:00
|
|
|
rb_enable_interrupt();
|
2003-11-05 17:00:11 +03:00
|
|
|
}
|
2008-04-26 13:36:35 +04:00
|
|
|
#endif
|
2003-11-05 17:00:11 +03:00
|
|
|
|
2007-11-30 17:08:58 +03:00
|
|
|
void
|
* cont.c (rb_fiber_current), dln.c (dln_print_undef, dln_undefined),
eval.c (rb_iterator_p, rb_need_block), load.c: (Init_load), ruby.c
(uscore_get, rb_f_chop), st.c (stat_col), signal.c
(rb_signal_buff_size, ruby_sig_finalize), thread.c
(rb_thread_sleep_forever, rb_thread_sleep_deadly, rb_thread_alone):
protoized.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-01 15:51:44 +03:00
|
|
|
ruby_sig_finalize(void)
|
2007-11-30 17:08:58 +03:00
|
|
|
{
|
|
|
|
sighandler_t oldfunc;
|
|
|
|
|
|
|
|
oldfunc = ruby_signal(SIGINT, SIG_IGN);
|
|
|
|
if (oldfunc == sighandler) {
|
|
|
|
ruby_signal(SIGINT, SIG_DFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-29 11:57:24 +04:00
|
|
|
int ruby_enable_coredump = 0;
|
2010-10-13 06:04:10 +04:00
|
|
|
#ifndef RUBY_DEBUG_ENV
|
|
|
|
#define ruby_enable_coredump 0
|
2007-06-28 18:22:30 +04:00
|
|
|
#endif
|
|
|
|
|
2003-12-27 19:07:43 +03:00
|
|
|
/*
|
|
|
|
* Many operating systems allow signals to be sent to running
|
|
|
|
* processes. Some signals have a defined effect on the process, while
|
|
|
|
* others may be trapped at the code level and acted upon. For
|
|
|
|
* example, your process may trap the USR1 signal and use it to toggle
|
|
|
|
* debugging, and may use TERM to initiate a controlled shutdown.
|
|
|
|
*
|
|
|
|
* pid = fork do
|
|
|
|
* Signal.trap("USR1") do
|
|
|
|
* $debug = !$debug
|
|
|
|
* puts "Debug now: #$debug"
|
|
|
|
* end
|
|
|
|
* Signal.trap("TERM") do
|
|
|
|
* puts "Terminating..."
|
|
|
|
* shutdown()
|
|
|
|
* end
|
|
|
|
* # . . . do some work . . .
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Process.detach(pid)
|
|
|
|
*
|
|
|
|
* # Controlling program:
|
|
|
|
* Process.kill("USR1", pid)
|
|
|
|
* # ...
|
|
|
|
* Process.kill("USR1", pid)
|
|
|
|
* # ...
|
|
|
|
* Process.kill("TERM", pid)
|
|
|
|
*
|
|
|
|
* produces:
|
|
|
|
* Debug now: true
|
|
|
|
* Debug now: false
|
|
|
|
* Terminating...
|
|
|
|
*
|
|
|
|
* The list of available signal names and their interpretation is
|
|
|
|
* system dependent. Signal delivery semantics may also vary between
|
|
|
|
* systems; in particular signal delivery may not always be reliable.
|
|
|
|
*/
|
1998-01-16 15:13:05 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
Init_signal(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-08-23 10:02:15 +04:00
|
|
|
VALUE mSignal = rb_define_module("Signal");
|
|
|
|
|
|
|
|
rb_define_global_function("trap", sig_trap, -1);
|
|
|
|
rb_define_module_function(mSignal, "trap", sig_trap, -1);
|
|
|
|
rb_define_module_function(mSignal, "list", sig_list, 0);
|
2012-11-19 13:43:53 +04:00
|
|
|
rb_define_module_function(mSignal, "signame", sig_signame, 1);
|
2001-08-23 10:02:15 +04:00
|
|
|
|
2007-04-19 21:37:03 +04:00
|
|
|
rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
|
2008-05-30 17:32:39 +04:00
|
|
|
rb_define_method(rb_eSignal, "signo", esignal_signo, 0);
|
2007-04-19 21:37:03 +04:00
|
|
|
rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message"));
|
|
|
|
rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1);
|
|
|
|
|
2002-01-21 10:44:06 +03:00
|
|
|
install_sighandler(SIGINT, sighandler);
|
2000-05-13 20:13:31 +04:00
|
|
|
#ifdef SIGHUP
|
2002-01-21 10:44:06 +03:00
|
|
|
install_sighandler(SIGHUP, sighandler);
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
2002-01-21 10:44:06 +03:00
|
|
|
install_sighandler(SIGQUIT, sighandler);
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
2006-10-18 17:59:19 +04:00
|
|
|
#ifdef SIGTERM
|
|
|
|
install_sighandler(SIGTERM, sighandler);
|
|
|
|
#endif
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifdef SIGALRM
|
2002-01-21 10:44:06 +03:00
|
|
|
install_sighandler(SIGALRM, sighandler);
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
2002-01-21 10:44:06 +03:00
|
|
|
install_sighandler(SIGUSR1, sighandler);
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
2002-01-21 10:44:06 +03:00
|
|
|
install_sighandler(SIGUSR2, sighandler);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2010-10-13 06:04:10 +04:00
|
|
|
if (!ruby_enable_coredump) {
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef SIGBUS
|
2011-07-02 23:59:05 +04:00
|
|
|
install_sighandler(SIGBUS, (sighandler_t)sigbus);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
2008-12-01 09:49:34 +03:00
|
|
|
# ifdef USE_SIGALTSTACK
|
2010-10-13 06:04:10 +04:00
|
|
|
rb_register_sigaltstack(GET_THREAD());
|
2008-12-01 09:49:34 +03:00
|
|
|
# endif
|
2010-10-13 06:04:10 +04:00
|
|
|
install_sighandler(SIGSEGV, (sighandler_t)sigsegv);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2007-06-28 18:22:30 +04:00
|
|
|
}
|
1999-10-12 08:53:36 +04:00
|
|
|
#ifdef SIGPIPE
|
2011-05-28 11:11:54 +04:00
|
|
|
install_sighandler(SIGPIPE, SIG_IGN);
|
1999-10-12 08:53:36 +04:00
|
|
|
#endif
|
2003-11-05 17:00:11 +03:00
|
|
|
|
2006-10-22 12:07:12 +04:00
|
|
|
#if defined(SIGCLD)
|
2003-11-05 17:00:11 +03:00
|
|
|
init_sigchld(SIGCLD);
|
2006-10-22 12:07:12 +04:00
|
|
|
#elif defined(SIGCHLD)
|
2003-11-05 17:00:11 +03:00
|
|
|
init_sigchld(SIGCHLD);
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|