aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--signal.c9
-rw-r--r--test/ruby/test_signal.rb8
2 files changed, 15 insertions, 2 deletions
diff --git a/signal.c b/signal.c
index feba176419..4099a5da2e 100644
--- a/signal.c
+++ b/signal.c
@@ -1089,8 +1089,13 @@ trap(int sig, sighandler_t func, VALUE command)
* atomically. In current implementation, we only need to don't call
* RUBY_VM_CHECK_INTS().
*/
- oldfunc = ruby_signal(sig, func);
- if (oldfunc == SIG_ERR) rb_sys_fail_str(rb_signo2signm(sig));
+ if (sig == 0) {
+ oldfunc = SIG_ERR;
+ }
+ else {
+ oldfunc = ruby_signal(sig, func);
+ if (oldfunc == SIG_ERR) rb_sys_fail_str(rb_signo2signm(sig));
+ }
oldcmd = vm->trap_list[sig].cmd;
switch (oldcmd) {
case 0:
diff --git a/test/ruby/test_signal.rb b/test/ruby/test_signal.rb
index 5c6d379cac..93a497a831 100644
--- a/test/ruby/test_signal.rb
+++ b/test/ruby/test_signal.rb
@@ -177,6 +177,14 @@ class TestSignal < Test::Unit::TestCase
end
end
+ def test_sigexit
+ assert_in_out_err([], 'Signal.trap(:EXIT) {print "OK"}', ["OK"])
+ assert_in_out_err([], 'Signal.trap("EXIT") {print "OK"}', ["OK"])
+ assert_in_out_err([], 'Signal.trap(:SIGEXIT) {print "OK"}', ["OK"])
+ assert_in_out_err([], 'Signal.trap("SIGEXIT") {print "OK"}', ["OK"])
+ assert_in_out_err([], 'Signal.trap(0) {print "OK"}', ["OK"])
+ end
+
def test_kill_immediately_before_termination
Signal.list[sig = "USR1"] or sig = "INT"
assert_in_out_err(["-e", <<-"end;"], "", %w"foo")