X-Git-Url: http://git.hcoop.net/bpt/guile.git/blobdiff_plain/003d1fd0462541a64f24c58c55ae71af5afd67d4..fdc2839563bd8c821221a4869f27255ae77f757b:/libguile/scmsigs.c diff --git a/libguile/scmsigs.c b/libguile/scmsigs.c index 7e63e7212..bdbf525e7 100644 --- a/libguile/scmsigs.c +++ b/libguile/scmsigs.c @@ -1,15 +1,15 @@ -/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - * +/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, @@ -44,16 +44,18 @@ -#include #include -#include "_scm.h" +#include -#include "async.h" -#include "eval.h" -#include "vectors.h" +#include "libguile/_scm.h" -#include "validate.h" -#include "scmsigs.h" +#include "libguile/async.h" +#include "libguile/eval.h" +#include "libguile/root.h" +#include "libguile/vectors.h" + +#include "libguile/validate.h" +#include "libguile/scmsigs.h" #ifdef HAVE_UNISTD_H #include @@ -74,13 +76,6 @@ int usleep (); -#ifdef USE_MIT_PTHREADS -#undef signal -#define signal pthread_signal -#endif - - - /* SIGRETTYPE is the type that signal handlers return. See */ #ifdef RETSIGTYPE @@ -114,7 +109,7 @@ static SCM *signal_handlers; #ifdef HAVE_SIGACTION static struct sigaction orig_handlers[NSIG]; #else -static SIGRETTYPE (*orig_handlers)(int)[NSIG]; +static SIGRETTYPE (*orig_handlers[NSIG])(int); #endif static SIGRETTYPE @@ -122,6 +117,7 @@ take_signal (int signum) { int saved_errno = errno; SCM ignored; + if (!scm_ints_disabled) { /* For reasons of speed, the SCM_NEWCELL macro doesn't defer @@ -171,18 +167,16 @@ sys_deliver_signals (void) #ifndef HAVE_SIGACTION signal (i, take_signal); #endif - scm_apply (SCM_VELTS (*signal_handlers)[i], - scm_listify (SCM_MAKINUM (i), SCM_UNDEFINED), - SCM_EOL); + scm_call_1 (SCM_VELTS (*signal_handlers)[i], SCM_MAKINUM (i)); } } return SCM_UNSPECIFIED; } /* user interface for installation of signal handlers. */ -SCM_DEFINE (scm_sigaction, "sigaction", 1, 2, 0, +SCM_DEFINE (scm_sigaction, "sigaction", 1, 2, 0, (SCM signum, SCM handler, SCM flags), - "Install or report the signal hander for a specified signal.\n\n" + "Install or report the signal handler for a specified signal.\n\n" "@var{signum} is the signal number, which can be specified using the value\n" "of variables such as @code{SIGINT}.\n\n" "If @var{action} is omitted, @code{sigaction} returns a pair: the\n" @@ -197,7 +191,7 @@ SCM_DEFINE (scm_sigaction, "sigaction", 1, 2, 0, "@code{SIG_IGN} (ignore), or @code{#f} to restore whatever signal handler\n" "was installed before @code{sigaction} was first used. Flags can\n" "optionally be specified for the new handler (@code{SA_RESTART} will\n" - "always be added if it's available and the system is using rstartable\n" + "always be added if it's available and the system is using restartable\n" "system calls.) The return value is a pair with information about the\n" "old handler as described above.\n\n" "This interface does not provide access to the \"signal blocking\"\n" @@ -240,10 +234,10 @@ SCM_DEFINE (scm_sigaction, "sigaction", 1, 2, 0, old_handler = scheme_handlers[csig]; if (SCM_UNBNDP (handler)) query_only = 1; - else if (scm_integer_p (handler) == SCM_BOOL_T) + else if (SCM_EQ_P (scm_integer_p (handler), SCM_BOOL_T)) { - if (SCM_NUM2LONG (2,handler) == (long) SIG_DFL - || SCM_NUM2LONG (2,handler) == (long) SIG_IGN) + if (SCM_NUM2LONG (2, handler) == (long) SIG_DFL + || SCM_NUM2LONG (2, handler) == (long) SIG_IGN) { #ifdef HAVE_SIGACTION action.sa_handler = (SIGRETTYPE (*) (int)) SCM_INUM (handler); @@ -277,7 +271,7 @@ SCM_DEFINE (scm_sigaction, "sigaction", 1, 2, 0, scheme_handlers[csig] = SCM_BOOL_F; } #endif - } + } else { SCM_VALIDATE_NIM (2,handler); @@ -292,6 +286,33 @@ SCM_DEFINE (scm_sigaction, "sigaction", 1, 2, 0, #endif scheme_handlers[csig] = handler; } + + /* XXX - Silently ignore setting handlers for `program error signals' + because they can't currently be handled by Scheme code. + */ + + switch (csig) + { + /* This list of program error signals is from the GNU Libc + Reference Manual */ + case SIGFPE: + case SIGILL: + case SIGSEGV: + case SIGBUS: + case SIGABRT: +#if defined(SIGIOT) && (SIGIOT != SIGABRT) + case SIGIOT: +#endif + case SIGTRAP: +#ifdef SIGEMT + case SIGEMT: +#endif +#ifdef SIGSYS + case SIGSYS: +#endif + query_only = 1; + } + #ifdef HAVE_SIGACTION if (query_only) { @@ -325,21 +346,21 @@ SCM_DEFINE (scm_sigaction, "sigaction", 1, 2, 0, orig_handlers[csig] = old_chandler; } if (old_chandler == SIG_DFL || old_chandler == SIG_IGN) - old_handler = scm_long2num (old_chandler); + old_handler = scm_long2num ((long) old_chandler); SCM_ALLOW_INTS; return scm_cons (old_handler, SCM_MAKINUM (0)); #endif } #undef FUNC_NAME -SCM_DEFINE (scm_restore_signals, "restore-signals", 0, 0, 0, +SCM_DEFINE (scm_restore_signals, "restore-signals", 0, 0, 0, (void), "Return all signal handlers to the values they had before any call to\n" "@code{sigaction} was made. The return value is unspecified.") #define FUNC_NAME s_scm_restore_signals { int i; - SCM *scheme_handlers = SCM_VELTS (*signal_handlers); + SCM *scheme_handlers = SCM_VELTS (*signal_handlers); for (i = 0; i < NSIG; i++) { @@ -365,7 +386,7 @@ SCM_DEFINE (scm_restore_signals, "restore-signals", 0, 0, 0, } #undef FUNC_NAME -SCM_DEFINE (scm_alarm, "alarm", 1, 0, 0, +SCM_DEFINE (scm_alarm, "alarm", 1, 0, 0, (SCM i), "Set a timer to raise a @code{SIGALRM} signal after the specified\n" "number of seconds (an integer). It's advisable to install a signal\n" @@ -385,7 +406,7 @@ SCM_DEFINE (scm_alarm, "alarm", 1, 0, 0, #undef FUNC_NAME #ifdef HAVE_PAUSE -SCM_DEFINE (scm_pause, "pause", 0, 0, 0, +SCM_DEFINE (scm_pause, "pause", 0, 0, 0, (), "Pause the current process (thread?) until a signal arrives whose\n" "action is to either terminate the current process or invoke a\n" @@ -398,7 +419,7 @@ SCM_DEFINE (scm_pause, "pause", 0, 0, 0, #undef FUNC_NAME #endif -SCM_DEFINE (scm_sleep, "sleep", 1, 0, 0, +SCM_DEFINE (scm_sleep, "sleep", 1, 0, 0, (SCM i), "Wait for the given number of seconds (an integer) or until a signal\n" "arrives. The return value is zero if the time elapses or the number\n" @@ -417,10 +438,10 @@ SCM_DEFINE (scm_sleep, "sleep", 1, 0, 0, #undef FUNC_NAME #if defined(USE_THREADS) || defined(HAVE_USLEEP) -SCM_DEFINE (scm_usleep, "usleep", 1, 0, 0, +SCM_DEFINE (scm_usleep, "usleep", 1, 0, 0, (SCM i), - "Sleep for I microseconds.\n" - "`usleep' is not available on all platforms.") + "Sleep for I microseconds. @code{usleep} is not available on\n" + "all platforms.") #define FUNC_NAME s_scm_usleep { SCM_VALIDATE_INUM_MIN (1,i,0); @@ -446,9 +467,8 @@ SCM_DEFINE (scm_usleep, "usleep", 1, 0, 0, #undef FUNC_NAME #endif /* GUILE_ISELECT || HAVE_USLEEP */ -SCM_DEFINE (scm_raise, "raise", 1, 0, 0, +SCM_DEFINE (scm_raise, "raise", 1, 0, 0, (SCM sig), - "\n" "Sends a specified signal @var{sig} to the current process, where\n" "@var{sig} is as described for the kill procedure.") #define FUNC_NAME s_scm_raise @@ -471,11 +491,11 @@ scm_init_scmsigs () int i; signal_handlers = - SCM_CDRLOC (scm_sysintern ("signal-handlers", - scm_make_vector (SCM_MAKINUM (NSIG), - SCM_BOOL_F))); - thunk = scm_make_gsubr ("%deliver-signals", 0, 0, 0, - sys_deliver_signals); + SCM_VARIABLE_LOC (scm_c_define ("signal-handlers", + scm_c_make_vector (NSIG, SCM_BOOL_F))); + /* XXX - use scm_c_make_gsubr here instead of `define'? */ + thunk = scm_c_define_gsubr ("%deliver-signals", 0, 0, 0, + sys_deliver_signals); signal_async = scm_system_async (thunk); for (i = 0; i < NSIG; i++) @@ -490,7 +510,7 @@ scm_init_scmsigs () #ifdef HAVE_RESTARTABLE_SYSCALLS /* If HAVE_RESTARTABLE_SYSCALLS is defined, it's important that - signals really are restartable. don't rely on the same + signals really are restartable. don't rely on the same run-time that configure got: reset the default for every signal. */ #ifdef HAVE_SIGINTERRUPT @@ -502,7 +522,7 @@ scm_init_scmsigs () sigaction (i, NULL, &action); if (!(action.sa_flags & SA_RESTART)) { - action.sa_flags &= SA_RESTART; + action.sa_flags |= SA_RESTART; sigaction (i, &action, NULL); } } @@ -512,16 +532,24 @@ scm_init_scmsigs () #endif } - scm_sysintern ("NSIG", scm_long2num (NSIG)); - scm_sysintern ("SIG_IGN", scm_long2num ((long) SIG_IGN)); - scm_sysintern ("SIG_DFL", scm_long2num ((long) SIG_DFL)); + scm_c_define ("NSIG", scm_long2num (NSIG)); + scm_c_define ("SIG_IGN", scm_long2num ((long) SIG_IGN)); + scm_c_define ("SIG_DFL", scm_long2num ((long) SIG_DFL)); #ifdef SA_NOCLDSTOP - scm_sysintern ("SA_NOCLDSTOP", scm_long2num (SA_NOCLDSTOP)); + scm_c_define ("SA_NOCLDSTOP", scm_long2num (SA_NOCLDSTOP)); #endif #ifdef SA_RESTART - scm_sysintern ("SA_RESTART", scm_long2num (SA_RESTART)); + scm_c_define ("SA_RESTART", scm_long2num (SA_RESTART)); #endif -#include "scmsigs.x" +#ifndef SCM_MAGIC_SNARFER +#include "libguile/scmsigs.x" +#endif } + +/* + Local Variables: + c-file-style: "gnu" + End: +*/