mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
signal.c: send signal unless handled
* signal.c (rb_f_kill): should not ignore signal unless the default handler is registered. [ruby-dev:48592] [Bug #9820] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
559154310f
commit
998befe8e6
3 changed files with 24 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Oct 6 16:23:30 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* signal.c (rb_f_kill): should not ignore signal unless the
|
||||
default handler is registered. [ruby-dev:48592] [Bug #9820]
|
||||
|
||||
Mon Oct 6 16:07:11 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* test/ruby/test_string.rb (test_LSHIFT_neary_long_max): enable
|
||||
|
|
15
signal.c
15
signal.c
|
@ -357,6 +357,7 @@ ruby_default_signal(int sig)
|
|||
raise(sig);
|
||||
}
|
||||
|
||||
static RETSIGTYPE sighandler(int sig);
|
||||
static int signal_ignored(int sig);
|
||||
static void signal_enque(int sig);
|
||||
|
||||
|
@ -465,6 +466,7 @@ rb_f_kill(int argc, const VALUE *argv)
|
|||
rb_pid_t pid = NUM2PIDT(argv[i]);
|
||||
|
||||
if ((sig != 0) && (self != -1) && (pid == self)) {
|
||||
int t;
|
||||
/*
|
||||
* When target pid is self, many caller assume signal will be
|
||||
* delivered immediately and synchronously.
|
||||
|
@ -483,7 +485,11 @@ rb_f_kill(int argc, const VALUE *argv)
|
|||
ruby_kill(pid, sig);
|
||||
break;
|
||||
default:
|
||||
if (signal_ignored(sig)) break;
|
||||
t = signal_ignored(sig);
|
||||
if (t) {
|
||||
if (t < 0) ruby_kill(pid, sig);
|
||||
break;
|
||||
}
|
||||
signal_enque(sig);
|
||||
wakeup = 1;
|
||||
}
|
||||
|
@ -638,16 +644,19 @@ ruby_nativethread_signal(int signum, sighandler_t handler)
|
|||
static int
|
||||
signal_ignored(int sig)
|
||||
{
|
||||
sighandler_t func;
|
||||
#ifdef POSIX_SIGNAL
|
||||
struct sigaction old;
|
||||
(void)VALGRIND_MAKE_MEM_DEFINED(&old, sizeof(old));
|
||||
if (sigaction(sig, NULL, &old) < 0) return FALSE;
|
||||
return old.sa_handler == SIG_IGN;
|
||||
func = old.sa_handler;
|
||||
#else
|
||||
sighandler_t old = signal(sig, SIG_DFL);
|
||||
signal(sig, old);
|
||||
return old == SIG_IGN;
|
||||
func = old;
|
||||
#endif
|
||||
if (func == SIG_IGN) return 1;
|
||||
return func == sighandler ? 0 : -1;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -279,5 +279,12 @@ EOS
|
|||
Process.kill(:INT, $$)
|
||||
end
|
||||
end;
|
||||
|
||||
if trap = Signal.list['TRAP']
|
||||
bug9820 = '[ruby-dev:48592] [Bug #9820]'
|
||||
status = assert_in_out_err(['-e', 'Process.kill(:TRAP, $$)'])
|
||||
assert_predicate(status, :signaled?, bug9820)
|
||||
assert_equal(trap, status.termsig, bug9820)
|
||||
end
|
||||
end if Process.respond_to?(:kill)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue