summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 02:03:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 02:03:34 +0000
commite41fde8b776e299342543a85f315646a25bec194 (patch)
tree1fe606167c6f6fbd3181431f52c0d978ea9a38dc
parenta718be06fac884b62435a7fc9bb251131163c06e (diff)
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
-rw-r--r--ChangeLog6
-rw-r--r--signal.c28
-rw-r--r--test/ruby/test_signal.rb8
3 files changed, 33 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 57b5697..a8c6629 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Sep 21 11:03:32 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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 <glass.saga@gmail.com>
* lib/tempfile.rb: define parameters appropriately and some
diff --git a/signal.c b/signal.c
index 0757385..296afdd 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 251a12d..e4cca02 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")