Permalink
Browse files

Make sure that ignoring a signal actually sets SIG_IGN as handler

This makes sure the signal never even arrives at the process.

Fixes #995
  • Loading branch information...
1 parent 484ae92 commit 703244bf0e37f9e9d48d4a820bac297253ca5dbf @dbussink dbussink committed Aug 2, 2011
Showing with 19 additions and 11 deletions.
  1. +2 −2 kernel/bootstrap/rubinius.rb
  2. +2 −2 kernel/common/signal.rb
  3. +3 −3 vm/builtin/system.cpp
  4. +1 −1 vm/builtin/system.hpp
  5. +4 −2 vm/signal.cpp
  6. +7 −1 vm/signal.hpp
@@ -4,9 +4,9 @@ def self.convert_to_names(list)
list.map! { |x| x.to_s }
end
- def self.watch_signal(sig)
+ def self.watch_signal(sig, ignored)
Ruby.primitive :vm_watch_signal
- watch_signal(sig.to_signal)
+ watch_signal(sig.to_signal, ignored)
end
def self.find_method(obj, name)
View
@@ -32,7 +32,7 @@ def self.trap(sig, prc=nil, &block)
old = @handlers.delete(number)
if number != Names["EXIT"]
- Rubinius.watch_signal(-number)
+ Rubinius.watch_signal(-number, prc.nil?)
end
return "DEFAULT" unless had_old
@@ -55,7 +55,7 @@ def self.trap(sig, prc=nil, &block)
@handlers[number] = prc
if number != Names["EXIT"]
- Rubinius.watch_signal number
+ Rubinius.watch_signal(number, prc.nil?)
end
return "DEFAULT" unless had_old
View
@@ -605,14 +605,14 @@ namespace rubinius {
#endif
}
- Object* System::vm_watch_signal(STATE, Fixnum* sig) {
+ Object* System::vm_watch_signal(STATE, Fixnum* sig, Object* ignored) {
SignalHandler* h = state->shared.signal_handler();
if(h) {
native_int i = sig->to_native();
if(i < 0) {
- h->add_signal(-i, true);
+ h->add_signal(-i, SignalHandler::eDefault);
} else {
- h->add_signal(i);
+ h->add_signal(i, ignored == Qtrue ? SignalHandler::eIgnore : SignalHandler::eCustom);
}
return Qtrue;
View
@@ -170,7 +170,7 @@ namespace rubinius {
static Fixnum* vm_memory_size(STATE, Object* obj);
// Ruby.primitive :vm_watch_signal
- static Object* vm_watch_signal(STATE, Fixnum* sig);
+ static Object* vm_watch_signal(STATE, Fixnum* sig, Object* ignored);
// Ruby.primitive :vm_time
static Object* vm_time(STATE);
View
@@ -124,16 +124,18 @@ namespace rubinius {
}
}
- void SignalHandler::add_signal(int sig, bool def) {
+ void SignalHandler::add_signal(int sig, HandlerType type) {
sigset_t sigs;
sigemptyset(&sigs);
sigaddset(&sigs, sig);
sigprocmask(SIG_UNBLOCK, &sigs, NULL);
struct sigaction action;
- if(def) {
+ if(type == eDefault) {
action.sa_handler = SIG_DFL;
+ } else if(type == eIgnore) {
+ action.sa_handler = SIG_IGN;
} else {
action.sa_handler = signal_tramp;
}
View
@@ -21,11 +21,17 @@ namespace rubinius {
bool exit_;
public:
+ enum HandlerType {
+ eDefault,
+ eIgnore,
+ eCustom
+ };
+
SignalHandler(VM* vm);
void perform();
- void add_signal(int sig, bool def=false);
+ void add_signal(int sig, HandlerType type = eCustom);
void handle_signal(int sig);
static void signal_tramp(int sig);

0 comments on commit 703244b

Please sign in to comment.