summaryrefslogtreecommitdiff
path: root/signal.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-01-20 04:59:39 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-01-20 04:59:39 +0000
commit210367ec889f5910e270d6ea2c7ddb8a8d939e61 (patch)
treefeb35473da45947378fbc02defe39bcd79ef600e /signal.c
parent9c5b1986a36c7a700b4c76817e35aa874ba7907c (diff)
This commit was generated by cvs2svn to compensate for changes in r372,
which included commits to RCS files with non-trunk default branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c141
1 files changed, 89 insertions, 52 deletions
diff --git a/signal.c b/signal.c
index e5621b4..d7ce492 100644
--- a/signal.c
+++ b/signal.c
@@ -9,16 +9,25 @@
************************************************/
#include "ruby.h"
-#include "sig.h"
+#include "rubysig.h"
#include <signal.h>
#include <stdio.h>
+#ifdef __BEOS__
+#undef SIGBUS
+#endif
+
#ifndef NSIG
-#ifdef DJGPP
-#define NSIG SIGMAX
-#else
-#define NSIG (_SIGMAX + 1) /* For QNX */
+# ifdef DJGPP
+# define NSIG SIGMAX
+# else
+# define NSIG (_SIGMAX + 1) /* For QNX */
+# endif
#endif
+
+#ifdef USE_CWGUSI
+# undef NSIG
+# define NSIG __signal_max
#endif
static struct signals {
@@ -171,31 +180,33 @@ signm2signo(nm)
}
VALUE
-f_kill(argc, argv)
+rb_f_kill(argc, argv)
int argc;
VALUE *argv;
{
+#ifdef USE_CWGUSI
+ rb_notimplement();
+#else
+ int negative = 0;
int sig;
int i;
char *s;
rb_secure(2);
if (argc < 2)
- ArgError("wrong # of arguments -- kill(sig, pid...)");
+ rb_raise(rb_eArgError, "wrong # of arguments -- kill(sig, pid...)");
switch (TYPE(argv[0])) {
case T_FIXNUM:
sig = FIX2UINT(argv[0]);
if (sig >= NSIG) {
s = rb_id2name(sig);
- if (!s) ArgError("Bad signal");
+ if (!s) rb_raise(rb_eArgError, "Bad signal");
goto str_signal;
}
break;
case T_STRING:
- {
- int negative = 0;
-
+ {
s = RSTRING(argv[0])->ptr;
if (s[0] == '-') {
negative++;
@@ -205,7 +216,7 @@ f_kill(argc, argv)
if (strncmp("SIG", s, 3) == 0)
s += 3;
if((sig = signm2signo(s)) == 0)
- ArgError("Unrecognized signal name `%s'", s);
+ rb_raise(rb_eArgError, "Unrecognized signal name `%s'", s);
if (negative)
sig = -sig;
@@ -213,7 +224,8 @@ f_kill(argc, argv)
break;
default:
- ArgError("bad signal type %s", rb_class2name(CLASS_OF(argv[0])));
+ rb_raise(rb_eArgError, "bad signal type %s",
+ rb_class2name(CLASS_OF(argv[0])));
break;
}
@@ -237,23 +249,26 @@ f_kill(argc, argv)
}
}
return INT2FIX(i-1);
+#endif /* USE_CWGUSI */
}
static VALUE trap_list[NSIG];
static int trap_pending_list[NSIG];
-int trap_pending;
-int trap_immediate;
-int prohibit_interrupt;
+int rb_trap_pending;
+int rb_trap_immediate;
+int rb_prohibit_interrupt;
void
-gc_mark_trap_list()
+rb_gc_mark_trap_list()
{
+#ifndef MACOS_UNUSE_SIGNAL
int i;
for (i=0; i<NSIG; i++) {
if (trap_list[i])
- gc_mark(trap_list[i]);
+ rb_gc_mark(trap_list[i]);
}
+#endif /* MACOS_UNUSE_SIGNAL */
}
#ifdef POSIX_SIGNAL
@@ -271,31 +286,32 @@ posix_signal(signum, handler)
}
#endif
+#ifdef USE_THREAD
+# define rb_interrupt rb_thread_interrupt
+# define rb_trap_eval rb_thread_trap_eval
+#endif
+
static RETSIGTYPE
sighandle(sig)
int sig;
{
if (sig >= NSIG ||(sig != SIGINT && !trap_list[sig]))
- Bug("trap_handler: Bad signal %d", sig);
+ rb_bug("trap_handler: Bad signal %d", sig);
#if !defined(POSIX_SIGNAL) && !defined(BSD_SIGNAL)
signal(sig, sighandle);
#endif
- if (trap_immediate) {
- trap_immediate = 0;
+ if (rb_trap_immediate) {
+ rb_trap_immediate = 0;
if (sig == SIGINT && !trap_list[SIGINT]) {
-#ifdef THREAD
- thread_interrupt();
-#else
rb_interrupt();
-#endif
}
rb_trap_eval(trap_list[sig], sig);
- trap_immediate = 1;
+ rb_trap_immediate = 1;
}
else {
- trap_pending++;
+ rb_trap_pending++;
trap_pending_list[sig]++;
}
}
@@ -305,7 +321,7 @@ static RETSIGTYPE
sigbus(sig)
int sig;
{
- Bug("Bus Error");
+ rb_bug("Bus Error");
}
#endif
@@ -314,41 +330,42 @@ static RETSIGTYPE
sigsegv(sig)
int sig;
{
- Bug("Segmentation fault");
+ rb_bug("Segmentation fault");
}
#endif
void
rb_trap_exit()
{
- if (trap_list[0])
- rb_eval_cmd(trap_list[0], ary_new3(1, INT2FIX(0)));
+#ifndef MACOS_UNUSE_SIGNAL
+ if (trap_list[0]) {
+ rb_eval_cmd(trap_list[0], rb_ary_new3(1, INT2FIX(0)));
+ }
+#endif
}
void
rb_trap_exec()
{
+#ifndef MACOS_UNUSE_SIGNAL
int i;
for (i=0; i<NSIG; i++) {
if (trap_pending_list[i]) {
trap_pending_list[i] = 0;
if (i == SIGINT && trap_list[SIGINT] == 0) {
-#ifdef THREAD
- thread_interrupt();
-#else
rb_interrupt();
-#endif
return;
}
rb_trap_eval(trap_list[i], i);
}
}
- trap_pending = 0;
+#endif /* MACOS_UNUSE_SIGNAL */
+ rb_trap_pending = 0;
}
struct trap_arg {
-#ifndef NT
+#if !defined(NT) && !defined(USE_CWGUSI)
# ifdef HAVE_SIGPROCMASK
sigset_t mask;
# else
@@ -358,6 +375,12 @@ struct trap_arg {
VALUE sig, cmd;
};
+# ifdef HAVE_SIGPROCMASK
+static sigset_t trap_last_mask;
+# else
+static int trap_last_mask;
+# endif
+
static RETSIGTYPE
sigexit()
{
@@ -415,17 +438,17 @@ trap(arg)
s += 3;
sig = signm2signo(s);
if (sig == 0 && strcmp(s, "EXIT") != 0)
- ArgError("Invalid signal SIG%s", s);
+ rb_raise(rb_eArgError, "Invalid signal SIG%s", s);
}
else {
sig = NUM2INT(arg->sig);
}
if (sig < 0 || sig > NSIG) {
- ArgError("Invalid signal no %d", sig);
+ rb_raise(rb_eArgError, "Invalid signal no %d", sig);
}
-#if defined(THREAD) && defined(HAVE_SETITIMER) && !defined(__BOW__)
+#if defined(USE_THREAD) && defined(HAVE_SETITIMER) && !defined(__BOW__)
if (sig == SIGVTALRM) {
- ArgError("SIGVTALRM reserved for Thread; cannot set handler");
+ rb_raise(rb_eArgError, "SIGVTALRM reserved for Thread; cannot set handler");
}
#endif
if (func == SIG_DFL) {
@@ -455,7 +478,7 @@ trap(arg)
trap_list[sig] = command;
/* enable at least specified signal. */
-#ifndef NT
+#if !defined(NT) && !defined(USE_CWGUSI)
#ifdef HAVE_SIGPROCMASK
sigdelset(&arg->mask, sig);
#else
@@ -465,8 +488,8 @@ trap(arg)
return old;
}
-#ifndef NT
-static void
+#if !defined(NT) && !defined(USE_CWGUSI)
+static VALUE
trap_ensure(arg)
struct trap_arg *arg;
{
@@ -476,11 +499,25 @@ trap_ensure(arg)
#else
sigsetmask(arg->mask);
#endif
+ trap_last_mask = arg->mask;
+ return 0;
}
#endif
+void
+rb_trap_restore_mask()
+{
+#ifndef NT
+# ifdef HAVE_SIGPROCMASK
+ sigprocmask(SIG_SETMASK, &trap_last_mask, NULL);
+# else
+ sigsetmask(trap_last_mask);
+# endif
+#endif
+}
+
static VALUE
-f_trap(argc, argv)
+rb_f_trap(argc, argv)
int argc;
VALUE *argv;
{
@@ -488,18 +525,18 @@ f_trap(argc, argv)
rb_secure(2);
if (argc == 0 || argc > 2) {
- ArgError("wrong # of arguments -- trap(sig, cmd)/trap(sig){...}");
+ rb_raise(rb_eArgError, "wrong # of arguments -- trap(sig, cmd)/trap(sig){...}");
}
arg.sig = argv[0];
if (argc == 1) {
- arg.cmd = f_lambda();
+ arg.cmd = rb_f_lambda();
}
else if (argc == 2) {
arg.cmd = argv[1];
}
-#ifndef NT
+#if !defined(NT) && !defined(USE_CWGUSI)
/* disable interrupt */
# ifdef HAVE_SIGPROCMASK
sigfillset(&arg.mask);
@@ -508,7 +545,7 @@ f_trap(argc, argv)
arg.mask = sigblock(~0);
# endif
- return rb_ensure(trap, &arg, trap_ensure, &arg);
+ return rb_ensure(trap, (VALUE)&arg, trap_ensure, (VALUE)&arg);
#else
return trap(&arg);
#endif
@@ -517,9 +554,8 @@ f_trap(argc, argv)
void
Init_signal()
{
- extern VALUE mKernel;
-
- rb_define_global_function("trap", f_trap, -1);
+#ifndef MACOS_UNUSE_SIGNAL
+ rb_define_global_function("trap", rb_f_trap, -1);
#ifdef POSIX_SIGNAL
posix_signal(SIGINT, sighandle);
#else
@@ -531,4 +567,5 @@ Init_signal()
#ifdef SIGSEGV
signal(SIGSEGV, sigsegv);
#endif
+#endif /* MACOS_UNUSE_SIGNAL */
}