1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2014-09-21 02:03:34 +00:00
parent a718be06fa
commit e41fde8b77
3 changed files with 33 additions and 9 deletions

View file

@ -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

View file

@ -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)

View file

@ -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")