diff --git a/eval.c b/eval.c index d5f2c4c..e563b27 100644 --- a/eval.c +++ b/eval.c @@ -441,8 +441,6 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg) JUMP_TAG(TAG_FATAL); } - rb_trap_restore_mask(); - if (tag != TAG_FATAL) { EXEC_EVENT_HOOK(th, RUBY_EVENT_RAISE, th->cfp->self, 0, 0); } diff --git a/eval_intern.h b/eval_intern.h index e1316bf..cc8b489 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -212,7 +212,6 @@ void rb_vm_set_progname(VALUE filename); void rb_thread_terminate_all(void); VALUE rb_vm_top_self(); VALUE rb_vm_cbase(void); -void rb_trap_restore_mask(void); #ifndef CharNext /* defined as CharNext[AW] on Windows. */ #define CharNext(p) ((p) + mblen((p), RUBY_MBCHAR_MAXSIZE)) diff --git a/lib/test/unit/parallel.rb b/lib/test/unit/parallel.rb index e433779..bdf08fb 100644 --- a/lib/test/unit/parallel.rb +++ b/lib/test/unit/parallel.rb @@ -74,7 +74,6 @@ module Test @@stop_auto_run = true @opts = @options.dup - Signal.trap(:INT,"IGNORE") @old_loadpath = [] begin @stdout = increment_io(STDOUT) diff --git a/process.c b/process.c index 0f60cfb..4965ae6 100644 --- a/process.c +++ b/process.c @@ -989,9 +989,9 @@ static int forked_child = 0; * Therefore we have to kill internal threads at once. [ruby-core: 10583] */ #define before_exec() \ - (rb_enable_interrupt(), (void)(forked_child ? 0 : (rb_thread_stop_timer_thread(), 1))) + ((void)(forked_child ? 0 : (rb_thread_stop_timer_thread(), 1))) #define after_exec() \ - (rb_thread_reset_timer_thread(), rb_thread_start_timer_thread(), forked_child = 0, rb_disable_interrupt()) + (rb_thread_reset_timer_thread(), rb_thread_start_timer_thread(), forked_child = 0) #define before_fork() before_exec() #define after_fork() (GET_THREAD()->thrown_errinfo = 0, after_exec()) @@ -2915,43 +2915,12 @@ rb_f_abort(int argc, VALUE *argv) void rb_syswait(rb_pid_t pid) { - static int overriding; -#ifdef SIGHUP - RETSIGTYPE (*hfunc)(int) = 0; -#endif -#ifdef SIGQUIT - RETSIGTYPE (*qfunc)(int) = 0; -#endif - RETSIGTYPE (*ifunc)(int) = 0; int status; - int i, hooked = FALSE; - - if (!overriding) { -#ifdef SIGHUP - hfunc = signal(SIGHUP, SIG_IGN); -#endif -#ifdef SIGQUIT - qfunc = signal(SIGQUIT, SIG_IGN); -#endif - ifunc = signal(SIGINT, SIG_IGN); - overriding = TRUE; - hooked = TRUE; - } + int i; do { i = rb_waitpid(pid, &status, 0); } while (i == -1 && errno == EINTR); - - if (hooked) { -#ifdef SIGHUP - signal(SIGHUP, hfunc); -#endif -#ifdef SIGQUIT - signal(SIGQUIT, qfunc); -#endif - signal(SIGINT, ifunc); - overriding = FALSE; - } } static VALUE diff --git a/signal.c b/signal.c index c7ad67f..02c963c 100644 --- a/signal.c +++ b/signal.c @@ -312,6 +312,12 @@ interrupt_init(int argc, VALUE *argv, VALUE self) void ruby_default_signal(int sig) { + sigset_t sigmask; + + sigemptyset(&sigmask); + sigaddset(&sigmask, sig); + pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL); + signal(sig, SIG_DFL); raise(sig); } @@ -535,14 +541,6 @@ rb_signal_buff_size(void) return signal_buff.size; } -#if USE_TRAP_MASK -# ifdef HAVE_SIGPROCMASK -static sigset_t trap_last_mask; -# else -static int trap_last_mask; -# endif -#endif - #if HAVE_PTHREAD_H #include #endif @@ -623,14 +621,6 @@ sigsegv(int sig SIGINFO_ARG) } #endif -#ifdef SIGPIPE -static RETSIGTYPE -sigpipe(int sig) -{ - /* do nothing */ -} -#endif - static void signal_exec(VALUE cmd, int safe, int sig) { @@ -746,7 +736,7 @@ default_handler(int sig) #endif #ifdef SIGPIPE case SIGPIPE: - func = sigpipe; + func = SIG_IGN; break; #endif default: @@ -893,19 +883,10 @@ trap_ensure(struct trap_arg *arg) { /* enable interrupt */ pthread_sigmask(SIG_SETMASK, &arg->mask, NULL); - trap_last_mask = arg->mask; return 0; } #endif -void -rb_trap_restore_mask(void) -{ -#if USE_TRAP_MASK - pthread_sigmask(SIG_SETMASK, &trap_last_mask, NULL); -#endif -} - /* * call-seq: * Signal.trap( signal, command ) -> obj @@ -1038,7 +1019,6 @@ init_sigchld(int sig) #if USE_TRAP_MASK sigdelset(&mask, sig); pthread_sigmask(SIG_SETMASK, &mask, NULL); - trap_last_mask = mask; #endif } #endif @@ -1143,7 +1123,7 @@ Init_signal(void) #endif } #ifdef SIGPIPE - install_sighandler(SIGPIPE, sigpipe); + install_sighandler(SIGPIPE, SIG_IGN); #endif #if defined(SIGCLD) @@ -1151,4 +1131,6 @@ Init_signal(void) #elif defined(SIGCHLD) init_sigchld(SIGCHLD); #endif + + rb_disable_interrupt(); } diff --git a/thread_pthread.c b/thread_pthread.c index d14f2b2..4416f24 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -996,6 +996,9 @@ thread_timer(void *dummy) { struct timespec timeout_10ms; + /* only timer thread recieve signal */ + rb_enable_interrupt(); + timeout_10ms.tv_sec = 0; timeout_10ms.tv_nsec = 10 * 1000 * 1000; @@ -1024,8 +1027,6 @@ thread_timer(void *dummy) static void rb_thread_create_timer_thread(void) { - rb_enable_interrupt(); - if (!timer_thread_id) { pthread_attr_t attr; int err; @@ -1046,7 +1047,6 @@ rb_thread_create_timer_thread(void) native_cond_wait(&timer_thread_cond, &timer_thread_lock); native_mutex_unlock(&timer_thread_lock); } - rb_disable_interrupt(); /* only timer thread recieve signal */ } static int diff --git a/vm_eval.c b/vm_eval.c index 54debd7..35e5ebf 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1442,7 +1442,6 @@ rb_throw_obj(VALUE tag, VALUE value) RB_GC_GUARD(desc); rb_raise(rb_eArgError, "uncaught throw %s", RSTRING_PTR(desc)); } - rb_trap_restore_mask(); th->errinfo = NEW_THROW_OBJECT(tag, 0, TAG_THROW); JUMP_TAG(TAG_THROW);