summaryrefslogtreecommitdiff
path: root/signal.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 02:42:40 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 02:42:40 (GMT)
commitae0299e3062bfb2e298b485187cb87ee4606cf31 (patch)
treee13258b239012f501453a4783e40b24b8efaf1a8 /signal.c
parente539565d9a69d9a355e747d016228926467348ab (diff)
signal.c: raise SystemCallError for all failures
* signal.c (ruby_signal): return SIG_ERR as well as signal(2). * signal.c (trap): raise SystemCallError for all failures when called as a method. * signal.c (Init_signal): fail by [BUG] only if initialization is failed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/signal.c b/signal.c
index 296afdd..feba176 100644
--- a/signal.c
+++ b/signal.c
@@ -606,13 +606,7 @@ ruby_signal(int signum, sighandler_t handler)
}
(void)VALGRIND_MAKE_MEM_DEFINED(&old, sizeof(old));
if (sigaction(signum, &sigact, &old) < 0) {
- int e = errno;
- if (e == EINVAL) {
- rb_syserr_fail_str(e, rb_signo2signm(signum));
- }
- else if (e != 0) {
- rb_bug_errno("sigaction", e);
- }
+ return SIG_ERR;
}
if (old.sa_flags & SA_SIGINFO)
return (sighandler_t)old.sa_sigaction;
@@ -1096,6 +1090,7 @@ trap(int sig, sighandler_t func, VALUE command)
* RUBY_VM_CHECK_INTS().
*/
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:
@@ -1235,7 +1230,7 @@ sig_list(void)
return h;
}
-static void
+static int
install_sighandler(int signum, sighandler_t handler)
{
sighandler_t old;
@@ -1243,21 +1238,25 @@ install_sighandler(int signum, sighandler_t handler)
/* At this time, there is no subthread. Then sigmask guarantee atomics. */
rb_disable_interrupt();
old = ruby_signal(signum, handler);
+ if (old == SIG_ERR) return -1;
/* signal handler should be inherited during exec. */
if (old != SIG_DFL) {
ruby_signal(signum, old);
}
rb_enable_interrupt();
+ return 0;
}
+#define install_sighandler(signum, handler) (install_sighandler(signum, handler) ? rb_bug(#signum) : (void)0)
#if defined(SIGCLD) || defined(SIGCHLD)
-static void
+static int
init_sigchld(int sig)
{
sighandler_t oldfunc;
rb_disable_interrupt();
oldfunc = ruby_signal(sig, SIG_DFL);
+ if (oldfunc == SIG_ERR) return -1;
if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
ruby_signal(sig, oldfunc);
}
@@ -1265,7 +1264,9 @@ init_sigchld(int sig)
GET_VM()->trap_list[sig].cmd = 0;
}
rb_enable_interrupt();
+ return 0;
}
+#define init_sigchld(signum) (init_sigchld(signum) ? rb_bug(#signum) : (void)0)
#endif
void