From e41fde8b776e299342543a85f315646a25bec194 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 21 Sep 2014 02:03:34 +0000 Subject: [PATCH] signal.c: EINVAL is a failure * signal.c (ruby_signal): although "EINVAL from sigaction(2) is not a bug", but even it is a failure. pointed at toRuby/guRuby in RubyHiroba. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ signal.c | 28 +++++++++++++++++++--------- test/ruby/test_signal.rb | 8 ++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57b56974d6..a8c662967a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Sep 21 11:03:32 2014 Nobuyoshi Nakada + + * signal.c (ruby_signal): although "EINVAL from sigaction(2) is + not a bug", but even it is a failure. pointed at toRuby/guRuby + in RubyHiroba. + Sat Sep 20 03:00:26 2014 Masaki Matsushita * lib/tempfile.rb: define parameters appropriately and some diff --git a/signal.c b/signal.c index 075738576b..296afdd966 100644 --- a/signal.c +++ b/signal.c @@ -258,6 +258,18 @@ ruby_signal_name(int no) return signo2signm(no); } +static VALUE +rb_signo2signm(int signo) +{ + const char *const signm = signo2signm(signo); + if (signm) { + return rb_sprintf("SIG%s", signm); + } + else { + return rb_sprintf("SIG%u", signo); + } +} + /* * call-seq: * SignalException.new(sig_name) -> signal_exception @@ -290,13 +302,7 @@ esignal_init(int argc, VALUE *argv, VALUE self) sig = argv[1]; } else { - signm = signo2signm(signo); - if (signm) { - sig = rb_sprintf("SIG%s", signm); - } - else { - sig = rb_sprintf("SIG%u", signo); - } + sig = rb_signo2signm(signo); } } else { @@ -600,8 +606,12 @@ ruby_signal(int signum, sighandler_t handler) } (void)VALGRIND_MAKE_MEM_DEFINED(&old, sizeof(old)); if (sigaction(signum, &sigact, &old) < 0) { - if (errno != 0 && errno != EINVAL) { - rb_bug_errno("sigaction", errno); + int e = errno; + if (e == EINVAL) { + rb_syserr_fail_str(e, rb_signo2signm(signum)); + } + else if (e != 0) { + rb_bug_errno("sigaction", e); } } if (old.sa_flags & SA_SIGINFO) diff --git a/test/ruby/test_signal.rb b/test/ruby/test_signal.rb index 251a12db17..e4cca022b3 100644 --- a/test/ruby/test_signal.rb +++ b/test/ruby/test_signal.rb @@ -169,6 +169,14 @@ class TestSignal < Test::Unit::TestCase end end if Process.respond_to?(:kill) + %w"KILL STOP".each do |sig| + if Signal.list.key?(sig) + define_method("test_trap_uncatchable_#{sig}") do + assert_raise(Errno::EINVAL, "SIG#{sig} is not allowed to be caught") { Signal.trap(sig) {} } + end + end + end + def test_kill_immediately_before_termination Signal.list[sig = "USR1"] or sig = "INT" assert_in_out_err(["-e", <<-"end;"], "", %w"foo")