mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* signal.c: Standard signal handlers ignore signals on non-Ruby native
threads. When a handler is entried with ruby_signal() (like as the standard signal handlers), the handler for the signal is marked as it cannot accept non-Ruby native threads. If a handler can treat all signals on all native threads, please use ruby_nativethread_signal() to entry it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cc1e41d9bf
commit
7e70ac99de
3 changed files with 97 additions and 4 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Mon Feb 21 18:31:12 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
|
* signal.c: Standard signal handlers ignore signals on non-Ruby native
|
||||||
|
threads. When a handler is entried with ruby_signal() (like as the
|
||||||
|
standard signal handlers), the handler for the signal is marked as
|
||||||
|
it cannot accept non-Ruby native threads. If a handler can treat all
|
||||||
|
signals on all native threads, please use ruby_nativethread_signal()
|
||||||
|
to entry it.
|
||||||
|
|
||||||
Sun Feb 20 00:48:48 2005 Tanaka Akira <akr@m17n.org>
|
Sun Feb 20 00:48:48 2005 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
* lib/open-uri.rb (URI::FTP#buffer_open): access mechanism
|
* lib/open-uri.rb (URI::FTP#buffer_open): access mechanism
|
||||||
|
|
4
intern.h
4
intern.h
|
@ -400,6 +400,10 @@ void rb_gc_mark_trap_list _((void));
|
||||||
#ifdef POSIX_SIGNAL
|
#ifdef POSIX_SIGNAL
|
||||||
#define posix_signal ruby_posix_signal
|
#define posix_signal ruby_posix_signal
|
||||||
void posix_signal _((int, RETSIGTYPE (*)(int)));
|
void posix_signal _((int, RETSIGTYPE (*)(int)));
|
||||||
|
#ifdef HAVE_NATIVETHREAD
|
||||||
|
#define posix_nativethread_signal ruby_posix_nativethread_signal
|
||||||
|
void posix_nativethread_signal _((int, RETSIGTYPE (*)(int)));
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
void rb_trap_exit _((void));
|
void rb_trap_exit _((void));
|
||||||
void rb_trap_exec _((void));
|
void rb_trap_exec _((void));
|
||||||
|
|
88
signal.c
88
signal.c
|
@ -303,6 +303,7 @@ static struct {
|
||||||
int safe;
|
int safe;
|
||||||
} trap_list[NSIG];
|
} trap_list[NSIG];
|
||||||
static rb_atomic_t trap_pending_list[NSIG];
|
static rb_atomic_t trap_pending_list[NSIG];
|
||||||
|
static char rb_trap_accept_nativethreads[NSIG];
|
||||||
rb_atomic_t rb_trap_pending;
|
rb_atomic_t rb_trap_pending;
|
||||||
rb_atomic_t rb_trap_immediate;
|
rb_atomic_t rb_trap_immediate;
|
||||||
int rb_prohibit_interrupt = 1;
|
int rb_prohibit_interrupt = 1;
|
||||||
|
@ -334,6 +335,8 @@ ruby_signal(signum, handler)
|
||||||
{
|
{
|
||||||
struct sigaction sigact, old;
|
struct sigaction sigact, old;
|
||||||
|
|
||||||
|
rb_trap_accept_nativethreads[signum] = 0;
|
||||||
|
|
||||||
sigact.sa_handler = handler;
|
sigact.sa_handler = handler;
|
||||||
sigemptyset(&sigact.sa_mask);
|
sigemptyset(&sigact.sa_mask);
|
||||||
sigact.sa_flags = 0;
|
sigact.sa_flags = 0;
|
||||||
|
@ -360,8 +363,33 @@ posix_signal(signum, handler)
|
||||||
{
|
{
|
||||||
ruby_signal(signum, handler);
|
ruby_signal(signum, handler);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#define ruby_signal(sig,handler) signal((sig),(handler))
|
#ifdef HAVE_NATIVETHREAD
|
||||||
|
static sighandler_t
|
||||||
|
ruby_nativethread_signal(signum, handler)
|
||||||
|
int signum;
|
||||||
|
sighandler_t handler;
|
||||||
|
{
|
||||||
|
sighandler_t old;
|
||||||
|
|
||||||
|
old = ruby_signal(signum, handler);
|
||||||
|
rb_trap_accept_nativethreads[signum] = 1;
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
posix_nativethread_signal(signum, handler)
|
||||||
|
int signum;
|
||||||
|
sighandler_t handler;
|
||||||
|
{
|
||||||
|
ruby_nativethread_signal(signum, handler);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#else /* !POSIX_SIGNAL */
|
||||||
|
#define ruby_signal(sig,handler) {rb_trap_accept_nativethreads[sig] = 0; signal((sig),(handler));}
|
||||||
|
#ifdef HAVE_NATIVETHREAD
|
||||||
|
#define ruby_nativethread_signal(sig,handler) {signal((sig),(handler));rb_trap_accept_nativethreads[sig] = 1;}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void signal_exec _((int sig));
|
static void signal_exec _((int sig));
|
||||||
|
@ -408,13 +436,23 @@ sighandler(sig)
|
||||||
#else
|
#else
|
||||||
#define IN_MAIN_CONTEXT(f, a) f(a)
|
#define IN_MAIN_CONTEXT(f, a) f(a)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sig >= NSIG) {
|
if (sig >= NSIG) {
|
||||||
rb_bug("trap_handler: Bad signal %d", sig);
|
rb_bug("trap_handler: Bad signal %d", sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_NATIVETHREAD
|
||||||
|
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
|
||||||
|
/* ignore signals on non-Ruby native thread */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
|
#if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
|
||||||
ruby_signal(sig, sighandler);
|
if (rb_trap_accept_nativethreads[sig]) {
|
||||||
|
ruby_nativethread_signal(sig, sighandler);
|
||||||
|
} else {
|
||||||
|
ruby_signal(sig, sighandler);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (trap_list[sig].cmd == 0 && ATOMIC_TEST(rb_trap_immediate)) {
|
if (trap_list[sig].cmd == 0 && ATOMIC_TEST(rb_trap_immediate)) {
|
||||||
|
@ -433,6 +471,13 @@ static RETSIGTYPE
|
||||||
sigbus(sig)
|
sigbus(sig)
|
||||||
int sig;
|
int sig;
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_NATIVETHREAD
|
||||||
|
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
|
||||||
|
/* ignore signals on non-Ruby native thread */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
rb_bug("Bus Error");
|
rb_bug("Bus Error");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -443,6 +488,13 @@ static RETSIGTYPE
|
||||||
sigsegv(sig)
|
sigsegv(sig)
|
||||||
int sig;
|
int sig;
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_NATIVETHREAD
|
||||||
|
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
|
||||||
|
/* ignore signals on non-Ruby native thread */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
rb_bug("Segmentation fault");
|
rb_bug("Segmentation fault");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -508,6 +560,13 @@ static RETSIGTYPE
|
||||||
sigexit(sig)
|
sigexit(sig)
|
||||||
int sig;
|
int sig;
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_NATIVETHREAD
|
||||||
|
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
|
||||||
|
/* ignore signals on non-Ruby native thread */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
rb_exit(0);
|
rb_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -771,6 +830,27 @@ install_sighandler(signum, handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_NATIVETHREAD
|
||||||
|
static void
|
||||||
|
install_nativethread_sighandler(signum, handler)
|
||||||
|
int signum;
|
||||||
|
sighandler_t handler;
|
||||||
|
{
|
||||||
|
sighandler_t old;
|
||||||
|
int old_st;
|
||||||
|
|
||||||
|
old_st = rb_trap_accept_nativethreads[signum];
|
||||||
|
old = ruby_nativethread_signal(signum, handler);
|
||||||
|
if (old != SIG_DFL) {
|
||||||
|
if (old_st) {
|
||||||
|
ruby_nativethread_signal(signum, old);
|
||||||
|
} else {
|
||||||
|
ruby_signal(signum, old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_sigchld(sig)
|
init_sigchld(sig)
|
||||||
int sig;
|
int sig;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue