2000-05-09 00:53:16 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
signal.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Tue Dec 20 10:13:44 JST 1994
|
|
|
|
|
2003-01-16 02:34:03 -05:00
|
|
|
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
2000-05-01 05:42:38 -04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 00:53:16 -04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
2000-05-01 05:42:38 -04:00
|
|
|
|
2000-05-09 00:53:16 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-06-09 23:06:15 -04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/signal.h"
|
|
|
|
#include "ruby/node.h"
|
2007-04-19 13:37:03 -04:00
|
|
|
#include "yarvcore.h"
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifdef __BEOS__
|
|
|
|
#undef SIGBUS
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifndef NSIG
|
1999-01-19 23:59:39 -05:00
|
|
|
# ifdef DJGPP
|
|
|
|
# define NSIG SIGMAX
|
|
|
|
# else
|
|
|
|
# define NSIG (_SIGMAX + 1) /* For QNX */
|
|
|
|
# endif
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static struct signals {
|
2005-11-08 03:49:45 -05:00
|
|
|
const char *signm;
|
1998-01-16 07:13:05 -05:00
|
|
|
int signo;
|
|
|
|
} siglist [] = {
|
2005-06-12 12:56:06 -04:00
|
|
|
{"EXIT", 0},
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef SIGHUP
|
2002-04-24 00:54:16 -04:00
|
|
|
{"HUP", SIGHUP},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
2002-04-24 00:54:16 -04:00
|
|
|
{"INT", SIGINT},
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef SIGQUIT
|
2002-04-24 00:54:16 -04:00
|
|
|
{"QUIT", SIGQUIT},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
2002-04-24 00:54:16 -04:00
|
|
|
{"ILL", SIGILL},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
2002-04-24 00:54:16 -04:00
|
|
|
{"TRAP", SIGTRAP},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIOT
|
2002-04-24 00:54:16 -04:00
|
|
|
{"IOT", SIGIOT},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
2002-04-24 00:54:16 -04:00
|
|
|
{"ABRT", SIGABRT},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGEMT
|
2002-04-24 00:54:16 -04:00
|
|
|
{"EMT", SIGEMT},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
2002-04-24 00:54:16 -04:00
|
|
|
{"FPE", SIGFPE},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGKILL
|
2002-04-24 00:54:16 -04:00
|
|
|
{"KILL", SIGKILL},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
2002-04-24 00:54:16 -04:00
|
|
|
{"BUS", SIGBUS},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
2002-04-24 00:54:16 -04:00
|
|
|
{"SEGV", SIGSEGV},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
2002-04-24 00:54:16 -04:00
|
|
|
{"SYS", SIGSYS},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
2002-04-24 00:54:16 -04:00
|
|
|
{"PIPE", SIGPIPE},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
2002-04-24 00:54:16 -04:00
|
|
|
{"ALRM", SIGALRM},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
2002-04-24 00:54:16 -04:00
|
|
|
{"TERM", SIGTERM},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
2002-04-24 00:54:16 -04:00
|
|
|
{"URG", SIGURG},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSTOP
|
2002-04-24 00:54:16 -04:00
|
|
|
{"STOP", SIGSTOP},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
2002-04-24 00:54:16 -04:00
|
|
|
{"TSTP", SIGTSTP},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
2002-04-24 00:54:16 -04:00
|
|
|
{"CONT", SIGCONT},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
2002-04-24 00:54:16 -04:00
|
|
|
{"CHLD", SIGCHLD},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCLD
|
2002-04-24 00:54:16 -04:00
|
|
|
{"CLD", SIGCLD},
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
|
|
|
# ifdef SIGCHLD
|
2002-04-24 00:54:16 -04:00
|
|
|
{"CLD", SIGCHLD},
|
1998-01-16 07:13:05 -05:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
2002-04-24 00:54:16 -04:00
|
|
|
{"TTIN", SIGTTIN},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
2002-04-24 00:54:16 -04:00
|
|
|
{"TTOU", SIGTTOU},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
2002-04-24 00:54:16 -04:00
|
|
|
{"IO", SIGIO},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
2002-04-24 00:54:16 -04:00
|
|
|
{"XCPU", SIGXCPU},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXFSZ
|
2002-04-24 00:54:16 -04:00
|
|
|
{"XFSZ", SIGXFSZ},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGVTALRM
|
2002-04-24 00:54:16 -04:00
|
|
|
{"VTALRM", SIGVTALRM},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
2002-04-24 00:54:16 -04:00
|
|
|
{"PROF", SIGPROF},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
2002-04-24 00:54:16 -04:00
|
|
|
{"WINCH", SIGWINCH},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
2002-04-24 00:54:16 -04:00
|
|
|
{"USR1", SIGUSR1},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
2002-04-24 00:54:16 -04:00
|
|
|
{"USR2", SIGUSR2},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGLOST
|
2002-04-24 00:54:16 -04:00
|
|
|
{"LOST", SIGLOST},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGMSG
|
2002-04-24 00:54:16 -04:00
|
|
|
{"MSG", SIGMSG},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
2002-04-24 00:54:16 -04:00
|
|
|
{"PWR", SIGPWR},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPOLL
|
2002-04-24 00:54:16 -04:00
|
|
|
{"POLL", SIGPOLL},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGDANGER
|
2002-04-24 00:54:16 -04:00
|
|
|
{"DANGER", SIGDANGER},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGMIGRATE
|
2002-04-24 00:54:16 -04:00
|
|
|
{"MIGRATE", SIGMIGRATE},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPRE
|
2002-04-24 00:54:16 -04:00
|
|
|
{"PRE", SIGPRE},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGGRANT
|
2002-04-24 00:54:16 -04:00
|
|
|
{"GRANT", SIGGRANT},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGRETRACT
|
2002-04-24 00:54:16 -04:00
|
|
|
{"RETRACT", SIGRETRACT},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSOUND
|
2002-04-24 00:54:16 -04:00
|
|
|
{"SOUND", SIGSOUND},
|
2001-05-16 05:05:54 -04:00
|
|
|
#endif
|
|
|
|
#ifdef SIGINFO
|
2002-04-24 00:54:16 -04:00
|
|
|
{"INFO", SIGINFO},
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
2002-04-24 00:54:16 -04:00
|
|
|
{NULL, 0}
|
1998-01-16 07:13:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2005-11-08 03:49:45 -05:00
|
|
|
signm2signo(const char *nm)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct signals *sigs;
|
|
|
|
|
|
|
|
for (sigs = siglist; sigs->signm; sigs++)
|
|
|
|
if (strcmp(sigs->signm, nm) == 0)
|
|
|
|
return sigs->signo;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-08 03:49:45 -05: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 06:44:21 -04:00
|
|
|
signo2signm(int no)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
struct signals *sigs;
|
|
|
|
|
|
|
|
for (sigs = siglist; sigs->signm; sigs++)
|
|
|
|
if (sigs->signo == no)
|
|
|
|
return sigs->signm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-01 11: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 06:44:21 -04:00
|
|
|
ruby_signal_name(int no)
|
2003-09-28 22:44:49 -04:00
|
|
|
{
|
|
|
|
return signo2signm(no);
|
|
|
|
}
|
|
|
|
|
2007-04-19 13:37:03 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* SignalException.new(sig) => signal_exception
|
|
|
|
*
|
|
|
|
* Construct a new SignalException object. +sig+ should be a known
|
|
|
|
* signal name, or a signal number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (argc < 1 || argnum < argc) {
|
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
|
|
|
|
argc, argnum);
|
|
|
|
}
|
|
|
|
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 {
|
|
|
|
signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
|
|
|
|
if (strncmp(signm, "SIG", 3) == 0) signm += 3;
|
|
|
|
signo = signm2signo(signm);
|
|
|
|
if (!signo) {
|
|
|
|
rb_raise(rb_eArgError, "unsupported name `SIG%s'", signm);
|
|
|
|
}
|
|
|
|
if (SYMBOL_P(sig)) {
|
|
|
|
sig = rb_str_new2(signm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb_call_super(1, &sig);
|
|
|
|
rb_iv_set(self, "signo", INT2NUM(signo));
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
interrupt_init(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE args[2];
|
|
|
|
|
|
|
|
args[0] = INT2FIX(SIGINT);
|
2007-05-29 13:13:05 -04:00
|
|
|
rb_scan_args(argc, argv, "01", &args[1]);
|
|
|
|
return rb_call_super(2, args);
|
2007-04-19 13:37:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_default_signal(int sig)
|
|
|
|
{
|
|
|
|
#ifndef MACOS_UNUSE_SIGNAL
|
|
|
|
signal(sig, SIG_DFL);
|
|
|
|
raise(sig);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-01-02 01:01:12 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Process.kill(signal, pid, ...) => fixnum
|
|
|
|
*
|
|
|
|
* Sends the given signal to the specified process id(s), or to the
|
|
|
|
* current process if _pid_ is zero. _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
|
|
|
|
* processes. Not all signals are available on all platforms.
|
|
|
|
*
|
|
|
|
* pid = fork do
|
|
|
|
* Signal.trap("HUP") { puts "Ouch!"; exit }
|
|
|
|
* # ... do some work ...
|
|
|
|
* end
|
|
|
|
* # ...
|
|
|
|
* Process.kill("HUP", pid)
|
|
|
|
* Process.wait
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* Ouch!
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05: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 06:44:21 -04:00
|
|
|
rb_f_kill(int argc, VALUE *argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2007-04-19 13:37:03 -04:00
|
|
|
#ifndef HAS_KILLPG
|
|
|
|
#define killpg(pg, sig) kill(-(pg), sig)
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
int negative = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
int sig;
|
|
|
|
int i;
|
* 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-09 17:20:17 -04:00
|
|
|
const char *s;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
rb_secure(2);
|
|
|
|
if (argc < 2)
|
2001-11-19 00:03:03 -05:00
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments -- kill(sig, pid...)");
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (TYPE(argv[0])) {
|
|
|
|
case T_FIXNUM:
|
2000-09-19 03:54:28 -04:00
|
|
|
sig = FIX2INT(argv[0]);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
2000-03-13 02:18:45 -05:00
|
|
|
case T_SYMBOL:
|
|
|
|
s = rb_id2name(SYM2ID(argv[0]));
|
|
|
|
if (!s) rb_raise(rb_eArgError, "bad signal");
|
|
|
|
goto str_signal;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_STRING:
|
2006-08-31 06:47:44 -04:00
|
|
|
s = RSTRING_PTR(argv[0]);
|
2002-03-11 03:02:04 -05:00
|
|
|
if (s[0] == '-') {
|
|
|
|
negative++;
|
|
|
|
s++;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2002-03-11 03:02:04 -05:00
|
|
|
str_signal:
|
|
|
|
if (strncmp("SIG", s, 3) == 0)
|
|
|
|
s += 3;
|
|
|
|
if((sig = signm2signo(s)) == 0)
|
|
|
|
rb_raise(rb_eArgError, "unsupported name `SIG%s'", s);
|
|
|
|
|
|
|
|
if (negative)
|
|
|
|
sig = -sig;
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-03-11 03:02:04 -05:00
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
|
2002-12-19 04:20:20 -05:00
|
|
|
str = rb_check_string_type(argv[0]);
|
2002-03-11 03:02:04 -05:00
|
|
|
if (!NIL_P(str)) {
|
2006-08-31 06:47:44 -04:00
|
|
|
s = RSTRING_PTR(str);
|
2002-03-11 03:02:04 -05:00
|
|
|
goto str_signal;
|
|
|
|
}
|
|
|
|
rb_raise(rb_eArgError, "bad signal type %s",
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(argv[0]));
|
2002-03-11 03:02:04 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sig < 0) {
|
|
|
|
sig = -sig;
|
|
|
|
for (i=1; i<argc; i++) {
|
2007-04-19 13:37:03 -04:00
|
|
|
if (killpg(NUM2PIDT(argv[i]), sig) < 0)
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i=1; i<argc; i++) {
|
2007-04-19 13:37:03 -04:00
|
|
|
if (kill(NUM2PIDT(argv[i]), sig) < 0)
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
|
|
|
}
|
2007-04-19 13:37:03 -04:00
|
|
|
rb_thread_polling();
|
1998-01-16 07:13:05 -05:00
|
|
|
return INT2FIX(i-1);
|
|
|
|
}
|
|
|
|
|
2004-06-28 21:31:37 -04:00
|
|
|
static struct {
|
|
|
|
VALUE cmd;
|
|
|
|
} trap_list[NSIG];
|
2000-11-14 02:10:31 -05:00
|
|
|
static rb_atomic_t trap_pending_list[NSIG];
|
2005-02-21 04:33:34 -05:00
|
|
|
static char rb_trap_accept_nativethreads[NSIG];
|
2000-11-14 02:10:31 -05:00
|
|
|
rb_atomic_t rb_trap_pending;
|
|
|
|
rb_atomic_t rb_trap_immediate;
|
2003-05-19 00:52:55 -04:00
|
|
|
int rb_prohibit_interrupt = 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE
|
|
|
|
rb_get_trap_cmd(int 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 11:26:04 -05:00
|
|
|
return trap_list[sig].cmd;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05: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 06:44:21 -04:00
|
|
|
rb_gc_mark_trap_list(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifndef MACOS_UNUSE_SIGNAL
|
1998-01-16 07:13:05 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<NSIG; i++) {
|
2004-06-28 21:31:37 -04:00
|
|
|
if (trap_list[i].cmd)
|
|
|
|
rb_gc_mark(trap_list[i].cmd);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif /* MACOS_UNUSE_SIGNAL */
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2002-08-16 03:23:04 -04:00
|
|
|
#ifdef __dietlibc__
|
|
|
|
#define sighandler_t sh_t
|
|
|
|
#endif
|
|
|
|
|
2005-09-14 04:30:16 -04:00
|
|
|
typedef RETSIGTYPE (*sighandler_t)(int);
|
2002-01-21 02:44:06 -05:00
|
|
|
|
2002-01-21 08:59:41 -05:00
|
|
|
#ifdef POSIX_SIGNAL
|
2002-01-21 02:44:06 -05:00
|
|
|
static sighandler_t
|
2005-11-08 03:49:45 -05:00
|
|
|
ruby_signal(int signum, sighandler_t handler)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-01-21 02:44:06 -05:00
|
|
|
struct sigaction sigact, old;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-02-21 04:33:34 -05:00
|
|
|
rb_trap_accept_nativethreads[signum] = 0;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
sigact.sa_handler = handler;
|
|
|
|
sigemptyset(&sigact.sa_mask);
|
|
|
|
sigact.sa_flags = 0;
|
1999-10-12 00:53:36 -04:00
|
|
|
#ifdef SA_NOCLDWAIT
|
1999-10-13 02:44:42 -04:00
|
|
|
if (signum == SIGCHLD && handler == SIG_IGN)
|
1999-10-12 00:53:36 -04:00
|
|
|
sigact.sa_flags |= SA_NOCLDWAIT;
|
|
|
|
#endif
|
2002-01-21 02:44:06 -05:00
|
|
|
sigaction(signum, &sigact, &old);
|
|
|
|
return old.sa_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-11-08 03:49:45 -05:00
|
|
|
posix_signal(int signum, sighandler_t handler)
|
2002-01-21 02:44:06 -05:00
|
|
|
{
|
|
|
|
ruby_signal(signum, handler);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2005-02-21 04:33:34 -05:00
|
|
|
|
|
|
|
#else /* !POSIX_SIGNAL */
|
2005-02-22 09:50:33 -05:00
|
|
|
#define ruby_signal(sig,handler) (rb_trap_accept_nativethreads[sig] = 0, signal((sig),(handler)))
|
2005-02-21 04:33:34 -05:00
|
|
|
#ifdef HAVE_NATIVETHREAD
|
2005-02-22 09:50:33 -05: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 06:44:21 -04:00
|
|
|
ruby_nativethread_signal(int signum, sighandler_t handler)
|
2005-02-22 09:50:33 -05:00
|
|
|
{
|
|
|
|
sighandler_t old;
|
|
|
|
|
|
|
|
old = signal(signum, handler);
|
|
|
|
rb_trap_accept_nativethreads[signum] = 1;
|
|
|
|
return old;
|
|
|
|
}
|
2005-02-21 04:33:34 -05:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static RETSIGTYPE
|
|
|
|
sighandler(int sig)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
rb_vm_t *vm = GET_VM(); /* fix me for Multi-VM */
|
2006-12-31 10:02:22 -05:00
|
|
|
ATOMIC_INC(vm->signal_buff[sig]);
|
|
|
|
ATOMIC_INC(vm->bufferd_signal_size);
|
2007-02-23 01:59:12 -05:00
|
|
|
|
|
|
|
#if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
|
|
|
|
ruby_signal(sig, sighandler);
|
|
|
|
#endif
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
# ifdef HAVE_SIGPROCMASK
|
|
|
|
static sigset_t trap_last_mask;
|
|
|
|
# else
|
|
|
|
static int trap_last_mask;
|
|
|
|
# endif
|
2005-03-02 03:11:28 -05:00
|
|
|
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#if HAVE_PTHREAD_H
|
|
|
|
#include <pthread.h>
|
2005-09-24 19:11:11 -04:00
|
|
|
#endif
|
2005-03-02 03:11:28 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
void
|
|
|
|
rb_disable_interrupt(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-12-31 10:02:22 -05:00
|
|
|
#ifndef _WIN32
|
|
|
|
sigset_t mask;
|
|
|
|
sigfillset(&mask);
|
|
|
|
sigdelset(&mask, SIGVTALRM);
|
|
|
|
sigdelset(&mask, SIGSEGV);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &mask, NULL);
|
2005-02-21 04:33:34 -05:00
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2005-02-21 04:33:34 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
void
|
|
|
|
rb_enable_interrupt(void)
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
|
|
|
sigset_t mask;
|
|
|
|
sigemptyset(&mask);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &mask, NULL);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
rb_get_next_signal(rb_vm_t *vm)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
int i, sig = 0;
|
|
|
|
|
|
|
|
for (i=1; i<RUBY_NSIG; i++) {
|
|
|
|
if (vm->signal_buff[i] > 0) {
|
|
|
|
rb_disable_interrupt();
|
|
|
|
{
|
|
|
|
ATOMIC_DEC(vm->signal_buff[i]);
|
|
|
|
ATOMIC_DEC(vm->bufferd_signal_size);
|
|
|
|
}
|
|
|
|
rb_enable_interrupt();
|
|
|
|
sig = i;
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
return sig;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SIGBUS
|
|
|
|
static RETSIGTYPE
|
* 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 06:44:21 -04:00
|
|
|
sigbus(int sig)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_bug("Bus Error");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGSEGV
|
2006-12-31 10:02:22 -05:00
|
|
|
static int segv_received = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
static RETSIGTYPE
|
* 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 06:44:21 -04:00
|
|
|
sigsegv(int sig)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-12-31 10:02:22 -05:00
|
|
|
if (segv_received) {
|
|
|
|
fprintf(stderr, "SEGV recieved in SEGV handler\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
segv_received = 1;
|
|
|
|
rb_bug("Segmentation fault");
|
2005-02-21 04:33:34 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-02-19 02:03:06 -05:00
|
|
|
#ifdef SIGPIPE
|
|
|
|
static RETSIGTYPE
|
* 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 06:44:21 -04:00
|
|
|
sigpipe(int sig)
|
2001-02-19 02:03:06 -05:00
|
|
|
{
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-29 13:08:37 -04:00
|
|
|
static void
|
|
|
|
signal_exec(VALUE cmd, int sig)
|
|
|
|
{
|
|
|
|
rb_proc_t *proc;
|
|
|
|
VALUE signum = INT2FIX(sig);
|
|
|
|
GetProcPtr(cmd, proc);
|
|
|
|
th_invoke_proc(GET_THREAD(), proc, proc->block.self, 1, &signum);
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05: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 06:44:21 -04:00
|
|
|
rb_trap_exit(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifndef MACOS_UNUSE_SIGNAL
|
2004-06-28 21:31:37 -04:00
|
|
|
if (trap_list[0].cmd) {
|
|
|
|
VALUE trap_exit = trap_list[0].cmd;
|
2000-11-27 04:23:38 -05:00
|
|
|
|
2004-06-28 21:31:37 -04:00
|
|
|
trap_list[0].cmd = 0;
|
2007-05-29 13:08:37 -04:00
|
|
|
signal_exec(trap_exit, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05: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 01:37:46 -05:00
|
|
|
rb_signal_exec(rb_thread_t *th, int sig)
|
2006-12-31 10:02:22 -05: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 11:26:04 -05:00
|
|
|
VALUE cmd = rb_get_trap_cmd(sig);
|
2006-12-31 10:02:22 -05: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 11:26:04 -05:00
|
|
|
if (cmd == 0) {
|
|
|
|
switch (sig) {
|
|
|
|
case SIGINT:
|
|
|
|
rb_interrupt();
|
|
|
|
break;
|
2006-12-31 10:02:22 -05: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 11:26:04 -05:00
|
|
|
case SIGHUP:
|
2006-12-31 10:02:22 -05: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 11:26:04 -05:00
|
|
|
case SIGQUIT:
|
2006-12-31 10:02:22 -05:00
|
|
|
#endif
|
2007-04-19 13:37:03 -04:00
|
|
|
#ifdef SIGTERM
|
|
|
|
case SIGTERM:
|
|
|
|
#endif
|
2006-12-31 10:02:22 -05: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 11:26:04 -05:00
|
|
|
case SIGALRM:
|
2006-12-31 10:02:22 -05: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 11:26:04 -05:00
|
|
|
case SIGUSR1:
|
2006-12-31 10:02:22 -05: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 11:26:04 -05:00
|
|
|
case SIGUSR2:
|
2006-12-31 10:02:22 -05:00
|
|
|
#endif
|
2007-04-19 13:37:03 -04:00
|
|
|
rb_thread_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 11:26:04 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmd == Qundef) {
|
|
|
|
rb_thread_signal_exit(th);
|
|
|
|
}
|
|
|
|
else {
|
2007-05-29 13:08:37 -04:00
|
|
|
signal_exec(cmd, sig);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05: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 06:44:21 -04:00
|
|
|
rb_trap_exec(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifndef MACOS_UNUSE_SIGNAL
|
1998-01-16 07:13:05 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<NSIG; i++) {
|
|
|
|
if (trap_pending_list[i]) {
|
|
|
|
trap_pending_list[i] = 0;
|
* 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 11:26:04 -05:00
|
|
|
rb_signal_exec(GET_THREAD(), i);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif /* MACOS_UNUSE_SIGNAL */
|
|
|
|
rb_trap_pending = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct trap_arg {
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#ifndef _WIN32
|
1998-01-16 07:13:05 -05:00
|
|
|
# ifdef HAVE_SIGPROCMASK
|
|
|
|
sigset_t mask;
|
|
|
|
# else
|
|
|
|
int mask;
|
|
|
|
# endif
|
|
|
|
#endif
|
2007-05-29 13:08:37 -04:00
|
|
|
int sig;
|
|
|
|
sighandler_t func;
|
|
|
|
VALUE cmd;
|
1998-01-16 07:13:05 -05:00
|
|
|
};
|
|
|
|
|
2007-06-15 09: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:
|
|
|
|
func = sigbus;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
|
|
|
case SIGSEGV:
|
|
|
|
func = sigsegv;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
|
|
|
case SIGPIPE:
|
|
|
|
func = sigpipe;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
func = SIG_DFL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2007-06-15 05:58:10 -04:00
|
|
|
static RETSIGTYPE
|
|
|
|
wrong_trap(int sig)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-05-29 13:08:37 -04:00
|
|
|
static sighandler_t
|
2007-06-15 09:38:32 -04:00
|
|
|
trap_handler(VALUE *cmd, int sig)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2007-06-15 05:58:10 -04:00
|
|
|
sighandler_t func = wrong_trap;
|
2007-05-29 13:08:37 -04:00
|
|
|
VALUE command;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-05-29 13:08:37 -04:00
|
|
|
if (NIL_P(*cmd)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
func = SIG_IGN;
|
|
|
|
}
|
2005-06-30 02:20:09 -04:00
|
|
|
else {
|
2007-05-29 13:08:37 -04:00
|
|
|
command = rb_check_string_type(*cmd);
|
2005-06-30 02:20:09 -04:00
|
|
|
if (!NIL_P(command)) {
|
|
|
|
SafeStringValue(command); /* taint check */
|
2006-08-31 06:47:44 -04:00
|
|
|
switch (RSTRING_LEN(command)) {
|
2005-06-30 02:20:09 -04:00
|
|
|
case 0:
|
2007-06-15 09:38:32 -04:00
|
|
|
goto sig_ign;
|
2005-06-30 02:20:09 -04:00
|
|
|
break;
|
2007-06-15 09:38:32 -04:00
|
|
|
case 14:
|
|
|
|
if (strncmp(RSTRING_PTR(command), "SYSTEM_DEFAULT", 14) == 0) {
|
|
|
|
func = SIG_DFL;
|
|
|
|
*cmd = 0;
|
|
|
|
}
|
|
|
|
break;
|
2005-06-30 02:20:09 -04:00
|
|
|
case 7:
|
2006-08-31 06:47:44 -04:00
|
|
|
if (strncmp(RSTRING_PTR(command), "SIG_IGN", 7) == 0) {
|
2007-06-15 09:38:32 -04:00
|
|
|
sig_ign:
|
|
|
|
func = SIG_IGN;
|
|
|
|
*cmd = 0;
|
2005-06-30 02:20:09 -04:00
|
|
|
}
|
2006-08-31 06:47:44 -04:00
|
|
|
else if (strncmp(RSTRING_PTR(command), "SIG_DFL", 7) == 0) {
|
2007-06-15 09:38:32 -04:00
|
|
|
sig_dfl:
|
|
|
|
func = default_handler(sig);
|
|
|
|
*cmd = 0;
|
2005-06-30 02:20:09 -04:00
|
|
|
}
|
2006-08-31 06:47:44 -04:00
|
|
|
else if (strncmp(RSTRING_PTR(command), "DEFAULT", 7) == 0) {
|
2007-06-15 09:38:32 -04:00
|
|
|
goto sig_dfl;
|
2005-06-30 02:20:09 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
2006-08-31 06:47:44 -04:00
|
|
|
if (strncmp(RSTRING_PTR(command), "IGNORE", 6) == 0) {
|
2007-06-15 09:38:32 -04:00
|
|
|
goto sig_ign;
|
2005-06-30 02:20:09 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2006-08-31 06:47:44 -04:00
|
|
|
if (strncmp(RSTRING_PTR(command), "EXIT", 4) == 0) {
|
2007-05-29 13:08:37 -04:00
|
|
|
func = sighandler;
|
|
|
|
*cmd = Qundef;
|
2005-06-30 02:20:09 -04:00
|
|
|
}
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2007-06-15 05:58:10 -04:00
|
|
|
if (func == wrong_trap) {
|
2007-05-29 13:08:37 -04:00
|
|
|
rb_raise(rb_eArgError, "wrong trap - %s", RSTRING_PTR(command));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_proc_t *proc;
|
|
|
|
GetProcPtr(*cmd, proc);
|
|
|
|
func = sighandler;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-29 13:08:37 -04:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
trap_signm(VALUE vsig)
|
|
|
|
{
|
|
|
|
int sig = -1;
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
switch (TYPE(vsig)) {
|
2000-04-10 01:48:43 -04:00
|
|
|
case T_FIXNUM:
|
2007-05-29 13:08:37 -04:00
|
|
|
sig = FIX2INT(vsig);
|
|
|
|
if (sig < 0 || sig >= NSIG) {
|
|
|
|
rb_raise(rb_eArgError, "invalid signal number (%d)", sig);
|
|
|
|
}
|
2000-04-10 01:48:43 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_SYMBOL:
|
2007-05-29 13:08:37 -04:00
|
|
|
s = rb_id2name(SYM2ID(vsig));
|
2000-04-10 01:48:43 -04:00
|
|
|
if (!s) rb_raise(rb_eArgError, "bad signal");
|
|
|
|
goto str_signal;
|
|
|
|
|
2007-05-29 13:08:37 -04:00
|
|
|
default:
|
|
|
|
s = StringValuePtr(vsig);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-04-10 01:48:43 -04:00
|
|
|
str_signal:
|
1998-01-16 07:13:05 -05:00
|
|
|
if (strncmp("SIG", s, 3) == 0)
|
|
|
|
s += 3;
|
|
|
|
sig = signm2signo(s);
|
|
|
|
if (sig == 0 && strcmp(s, "EXIT") != 0)
|
2002-03-08 02:03:09 -05:00
|
|
|
rb_raise(rb_eArgError, "unsupported signal SIG%s", s);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-04-10 01:48:43 -04:00
|
|
|
|
2003-12-22 03:23:55 -05:00
|
|
|
#if defined(HAVE_SETITIMER)
|
1998-01-16 07:13:05 -05:00
|
|
|
if (sig == SIGVTALRM) {
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
rb_raise(rb_eArgError, "SIGVTALRM reserved for Thread; can't set handler");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
2007-05-29 13:08:37 -04:00
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
trap(struct trap_arg *arg)
|
|
|
|
{
|
|
|
|
sighandler_t oldfunc, func = arg->func;
|
|
|
|
VALUE oldcmd, command = arg->cmd;
|
|
|
|
int sig = arg->sig;
|
|
|
|
|
2003-03-25 10:25:18 -05:00
|
|
|
oldfunc = ruby_signal(sig, func);
|
2004-06-28 21:31:37 -04:00
|
|
|
oldcmd = trap_list[sig].cmd;
|
2007-05-29 13:08:37 -04:00
|
|
|
switch (oldcmd) {
|
|
|
|
case 0:
|
2003-03-25 10:25:18 -05:00
|
|
|
if (oldfunc == SIG_IGN) oldcmd = rb_str_new2("IGNORE");
|
|
|
|
else if (oldfunc == sighandler) oldcmd = rb_str_new2("DEFAULT");
|
|
|
|
else oldcmd = Qnil;
|
2007-05-29 13:08:37 -04:00
|
|
|
break;
|
|
|
|
case Qundef:
|
|
|
|
oldcmd = rb_str_new2("EXIT");
|
|
|
|
break;
|
2003-03-25 10:25:18 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2004-06-28 21:31:37 -04:00
|
|
|
trap_list[sig].cmd = command;
|
1998-01-16 07:13:05 -05:00
|
|
|
/* enable at least specified signal. */
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#ifndef _WIN32
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_SIGPROCMASK
|
|
|
|
sigdelset(&arg->mask, sig);
|
|
|
|
#else
|
|
|
|
arg->mask &= ~sigmask(sig);
|
|
|
|
#endif
|
|
|
|
#endif
|
2003-03-25 10:25:18 -05:00
|
|
|
return oldcmd;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#ifndef _WIN32
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
2005-11-08 03:49:45 -05:00
|
|
|
trap_ensure(struct trap_arg *arg)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
/* enable interrupt */
|
|
|
|
#ifdef HAVE_SIGPROCMASK
|
|
|
|
sigprocmask(SIG_SETMASK, &arg->mask, NULL);
|
|
|
|
#else
|
|
|
|
sigsetmask(arg->mask);
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
trap_last_mask = arg->mask;
|
|
|
|
return 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-19 23:59:39 -05: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 06:44:21 -04:00
|
|
|
rb_trap_restore_mask(void)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#ifndef _WIN32
|
1999-01-19 23:59:39 -05:00
|
|
|
# ifdef HAVE_SIGPROCMASK
|
|
|
|
sigprocmask(SIG_SETMASK, &trap_last_mask, NULL);
|
|
|
|
# else
|
|
|
|
sigsetmask(trap_last_mask);
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-12-27 11:07:43 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2007-06-15 10:33:59 -04:00
|
|
|
* Signal.trap( signal, command ) => obj
|
2003-12-27 11:07:43 -05:00
|
|
|
* Signal.trap( signal ) {| | block } => obj
|
|
|
|
*
|
|
|
|
* 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 10: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 09:38:32 -04:00
|
|
|
* If the command is ``SYSTEM_DEFAULT'', the operating system's default
|
|
|
|
* handler will be invoked.
|
2007-06-15 10:33:59 -04:00
|
|
|
* Otherwise, the given command or block will be run.
|
2003-12-27 11:07:43 -05: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 07:13:05 -05: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 06:44:21 -04:00
|
|
|
sig_trap(int argc, VALUE *argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct trap_arg arg;
|
|
|
|
|
|
|
|
rb_secure(2);
|
|
|
|
if (argc == 0 || argc > 2) {
|
2001-11-19 00:03:03 -05:00
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments -- trap(sig, cmd)/trap(sig){...}");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2007-05-29 13:08:37 -04:00
|
|
|
arg.sig = trap_signm(argv[0]);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (argc == 1) {
|
2003-06-16 03:14:50 -04:00
|
|
|
arg.cmd = rb_block_proc();
|
2007-05-29 13:08:37 -04:00
|
|
|
arg.func = sighandler;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else if (argc == 2) {
|
|
|
|
arg.cmd = argv[1];
|
2007-06-15 09:38:32 -04:00
|
|
|
arg.func = trap_handler(&arg.cmd, arg.sig);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2001-11-13 03:19:52 -05:00
|
|
|
if (OBJ_TAINTED(arg.cmd)) {
|
|
|
|
rb_raise(rb_eSecurityError, "Insecure: tainted signal trap");
|
|
|
|
}
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#ifndef _WIN32
|
1998-01-16 07:13:05 -05:00
|
|
|
/* disable interrupt */
|
|
|
|
# ifdef HAVE_SIGPROCMASK
|
|
|
|
sigfillset(&arg.mask);
|
|
|
|
sigprocmask(SIG_BLOCK, &arg.mask, &arg.mask);
|
|
|
|
# else
|
|
|
|
arg.mask = sigblock(~0);
|
|
|
|
# endif
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_ensure(trap, (VALUE)&arg, trap_ensure, (VALUE)&arg);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
|
|
|
return trap(&arg);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-12-27 11:07:43 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Signal.list => a_hash
|
|
|
|
*
|
|
|
|
* Returns a list of signal names mapped to the corresponding
|
|
|
|
* underlying signal numbers.
|
|
|
|
*
|
|
|
|
* Signal.list #=> {"ABRT"=>6, "ALRM"=>14, "BUS"=>7, "CHLD"=>17, "CLD"=>17, "CONT"=>18, "FPE"=>8, "HUP"=>1, "ILL"=>4, "INT"=>2, "IO"=>29, "IOT"=>6, "KILL"=>9, "PIPE"=>13, "POLL"=>29, "PROF"=>27, "PWR"=>30, "QUIT"=>3, "SEGV"=>11, "STOP"=>19, "SYS"=>31, "TERM"=>15, "TRAP"=>5, "TSTP"=>20, "TTIN"=>21, "TTOU"=>22, "URG"=>23, "USR1"=>10, "USR2"=>12, "VTALRM"=>26, "WINCH"=>28, "XCPU"=>24, "XFSZ"=>25}
|
|
|
|
*/
|
2001-08-23 02: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 06:44:21 -04:00
|
|
|
sig_list(void)
|
2001-08-23 02:02:15 -04:00
|
|
|
{
|
|
|
|
VALUE h = rb_hash_new();
|
|
|
|
struct signals *sigs;
|
|
|
|
|
|
|
|
for (sigs = siglist; sigs->signm; sigs++) {
|
|
|
|
rb_hash_aset(h, rb_str_new2(sigs->signm), INT2FIX(sigs->signo));
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2002-01-21 02:44:06 -05: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 06:44:21 -04:00
|
|
|
install_sighandler(int signum, sighandler_t handler)
|
2002-01-21 02:44:06 -05:00
|
|
|
{
|
|
|
|
sighandler_t old;
|
|
|
|
|
|
|
|
old = ruby_signal(signum, handler);
|
|
|
|
if (old != SIG_DFL) {
|
|
|
|
ruby_signal(signum, old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-05 09:00:11 -05: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 06:44:21 -04:00
|
|
|
init_sigchld(int sig)
|
2003-11-05 09:00:11 -05:00
|
|
|
{
|
|
|
|
sighandler_t oldfunc;
|
|
|
|
#ifndef _WIN32
|
|
|
|
# ifdef HAVE_SIGPROCMASK
|
|
|
|
sigset_t mask;
|
|
|
|
# else
|
|
|
|
int mask;
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
/* disable interrupt */
|
|
|
|
# ifdef HAVE_SIGPROCMASK
|
|
|
|
sigfillset(&mask);
|
|
|
|
sigprocmask(SIG_BLOCK, &mask, &mask);
|
|
|
|
# else
|
|
|
|
mask = sigblock(~0);
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
oldfunc = ruby_signal(sig, SIG_DFL);
|
|
|
|
if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
|
|
|
|
ruby_signal(sig, oldfunc);
|
|
|
|
} else {
|
2004-06-28 21:31:37 -04:00
|
|
|
trap_list[sig].cmd = 0;
|
2003-11-05 09:00:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#ifdef HAVE_SIGPROCMASK
|
|
|
|
sigdelset(&mask, sig);
|
|
|
|
sigprocmask(SIG_SETMASK, &mask, NULL);
|
|
|
|
#else
|
|
|
|
mask &= ~sigmask(sig);
|
|
|
|
sigsetmask(mask);
|
|
|
|
#endif
|
|
|
|
trap_last_mask = mask;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-12-27 11:07:43 -05: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 07:13:05 -05: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 06:44:21 -04:00
|
|
|
Init_signal(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifndef MACOS_UNUSE_SIGNAL
|
2001-08-23 02: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);
|
|
|
|
|
2007-04-19 13:37:03 -04:00
|
|
|
rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
|
|
|
|
rb_attr(rb_eSignal, rb_intern("signo"), 1, 0, 0);
|
|
|
|
rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message"));
|
|
|
|
rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1);
|
|
|
|
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGINT, sighandler);
|
2000-05-13 12:13:31 -04:00
|
|
|
#ifdef SIGHUP
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGHUP, sighandler);
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGQUIT, sighandler);
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
2006-10-18 09:59:19 -04:00
|
|
|
#ifdef SIGTERM
|
|
|
|
install_sighandler(SIGTERM, sighandler);
|
|
|
|
#endif
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef SIGALRM
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGALRM, sighandler);
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGUSR1, sighandler);
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGUSR2, sighandler);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-08-13 01:45:20 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef SIGBUS
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGBUS, sigbus);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGSEGV, sigsegv);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-10-12 00:53:36 -04:00
|
|
|
#ifdef SIGPIPE
|
2002-01-21 02:44:06 -05:00
|
|
|
install_sighandler(SIGPIPE, sigpipe);
|
1999-10-12 00:53:36 -04:00
|
|
|
#endif
|
2003-11-05 09:00:11 -05:00
|
|
|
|
2006-10-22 04:07:12 -04:00
|
|
|
#if defined(SIGCLD)
|
2003-11-05 09:00:11 -05:00
|
|
|
init_sigchld(SIGCLD);
|
2006-10-22 04:07:12 -04:00
|
|
|
#elif defined(SIGCHLD)
|
2003-11-05 09:00:11 -05:00
|
|
|
init_sigchld(SIGCHLD);
|
|
|
|
#endif
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif /* MACOS_UNUSE_SIGNAL */
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|