1999-09-14 09:32:05 -04:00
|
|
|
/* Need to define sig2interrupt vector.
|
|
|
|
** Interrupt-system mutators should probably hold interrupts while they
|
|
|
|
** operate.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "cstuff.h"
|
|
|
|
|
|
|
|
/* Make sure our exports match up w/the implementation: */
|
|
|
|
#include "sighandlers1.h"
|
|
|
|
|
|
|
|
/* Import the OS-dependent set of signals and their translations
|
|
|
|
** to S48 vm interrupts.
|
|
|
|
*/
|
|
|
|
#include "signals1.h"
|
|
|
|
|
|
|
|
extern int errno;
|
|
|
|
|
2000-09-01 03:07:57 -04:00
|
|
|
// JMG: extern s48_value Spending_interruptsS, Sinterrupt_handlersS;
|
1999-09-14 09:32:05 -04:00
|
|
|
|
|
|
|
/* Translate Unix signal numbers to S48 interrupt numbers. */
|
|
|
|
|
|
|
|
int sig2interrupt(int signal)
|
|
|
|
{
|
|
|
|
return ( signal < 0 || signal > max_sig ) ? -1 : sig2int[signal];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Set/Get signal handlers
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void scm_handle_sig(int sig)
|
|
|
|
{
|
|
|
|
/*fprintf(stderr, "scm_handle_sig(%d) = int %d\n", sig, sig2int[sig]);*/
|
1999-09-23 10:36:25 -04:00
|
|
|
//Spending_interruptsS |= (1<<sig2int[sig]);
|
|
|
|
fprintf(stderr, "scm_handle_sig was called with %d\n", sig);
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* handler_code: 0 => ignore, 1 => default, 2 => S48 VM */
|
|
|
|
|
|
|
|
/* Common code for two functions above. */
|
1999-09-15 20:20:37 -04:00
|
|
|
static s48_value scsh_ret_sig(int retval, struct sigaction *oldsa,
|
1999-09-14 09:32:05 -04:00
|
|
|
int *old_hc, int *oflags)
|
|
|
|
{
|
|
|
|
if( retval ) {
|
|
|
|
*old_hc = -1;
|
|
|
|
*oflags = -1;
|
1999-09-15 20:20:37 -04:00
|
|
|
return s48_enter_fixnum(errno);
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
|
|
|
if( oldsa->sa_handler == SIG_IGN ) *old_hc = 0;
|
|
|
|
else if( oldsa->sa_handler == SIG_DFL ) *old_hc = 1;
|
|
|
|
else if( oldsa->sa_handler == scm_handle_sig ) *old_hc = 2;
|
1999-09-15 20:20:37 -04:00
|
|
|
else *old_hc = s48_enter_fixnum(3); /* Unknown signal handler. */
|
1999-09-14 09:32:05 -04:00
|
|
|
|
|
|
|
*oflags = oldsa->sa_flags;
|
1999-09-15 20:20:37 -04:00
|
|
|
return S48_FALSE;
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-15 20:20:37 -04:00
|
|
|
s48_value scsh_set_sig(int sig, int handler_code, int flags,
|
1999-09-14 09:32:05 -04:00
|
|
|
int *old_hc, int *oflags)
|
|
|
|
{
|
|
|
|
struct sigaction new, old;
|
|
|
|
|
|
|
|
sigemptyset(&new.sa_mask); /* WTF */
|
|
|
|
new.sa_flags = flags;
|
|
|
|
|
|
|
|
switch( handler_code ) {
|
|
|
|
case 0: new.sa_handler = SIG_IGN; break;
|
|
|
|
case 1: new.sa_handler = SIG_DFL; break;
|
|
|
|
case 2: new.sa_handler = scm_handle_sig; break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Impossible handler_code in set_sig_handler: %d\n",
|
|
|
|
handler_code);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return scsh_ret_sig(sigaction(sig, &new, &old),
|
|
|
|
&old, old_hc, oflags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-15 20:20:37 -04:00
|
|
|
s48_value scsh_get_sig(int signal, int *old_hc, int *oflags)
|
1999-09-14 09:32:05 -04:00
|
|
|
{
|
|
|
|
struct sigaction old;
|
|
|
|
return scsh_ret_sig(sigaction(signal, NULL, &old),
|
|
|
|
&old, old_hc, oflags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This guy is responsible for making the default action for a
|
|
|
|
** Unix signal happen. Because S48's signal handler system is
|
|
|
|
** interposed between delivery-to-the-process and
|
|
|
|
** delivery-to-the-scheme-handler, when the user sets a signal
|
|
|
|
** handler to default, we install a Scheme proc that calls this
|
|
|
|
** guy, instead of just slapping a SIGDFL in as the Unix handler.
|
|
|
|
** We only have to do this for signals whose default isn't "ignore," i.e.:
|
|
|
|
** Posix: SIGALRM SIGHUP SIGINT SIGQUIT SIGTERM SIGUSR1 SIGUSR2
|
|
|
|
** Non-Posix: SIGINFO SIGPOLL SIGPROF SIGVTALRM SIGXCPU SIGXFSZ SIGIO
|
|
|
|
** This way, the S48 signal-blocking mechanism can work.
|
|
|
|
**
|
|
|
|
** Weird, I know.
|
|
|
|
*/
|
|
|
|
void do_default_sigaction(int signal)
|
|
|
|
{
|
|
|
|
sigset_t ss, old_ss;
|
|
|
|
struct sigaction default_action, old_action;
|
|
|
|
|
|
|
|
/* fprintf(stderr, "Doing default for signal %d\n", signal); */
|
|
|
|
|
|
|
|
sigfillset(&ss); /* Block everyone. */
|
|
|
|
sigprocmask(SIG_SETMASK, &ss, &old_ss);
|
|
|
|
|
|
|
|
default_action.sa_handler = SIG_DFL; /* Set for default. */
|
|
|
|
sigemptyset(&default_action.sa_mask);
|
|
|
|
default_action.sa_flags = 0;
|
|
|
|
sigaction(signal, &default_action, &old_action);
|
|
|
|
|
|
|
|
raise(signal); /* Raise the signal. */
|
|
|
|
sigdelset(&ss, signal);
|
|
|
|
sigprocmask(SIG_SETMASK, &ss, 0); /* Handle it. */
|
|
|
|
|
|
|
|
/* Most likely, we'll never get to here, as the default for
|
|
|
|
** the signals we're handling is "terminate," but we'll play it safe.
|
|
|
|
*/
|
|
|
|
sigaction(signal, &old_action, 0); /* Restore old handler, */
|
|
|
|
sigprocmask(SIG_SETMASK, &old_ss, 0); /* and mask. */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Set up the Unix signal system the way we want it for scsh. */
|
|
|
|
|
|
|
|
void install_scsh_handlers(void)
|
|
|
|
{
|
|
|
|
struct sigaction new;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sigemptyset(&new.sa_mask); /* WTF */
|
|
|
|
new.sa_handler = scm_handle_sig;
|
|
|
|
new.sa_flags = 0;
|
|
|
|
|
|
|
|
for(i=max_sig; i>=0; i--)
|
|
|
|
if( ( i != SIGINT ) && sig2int[i] ) {
|
|
|
|
/* This is a signal we want the S48 interrupt system to handle. */
|
|
|
|
sigaction(i, &new, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off SIGPIPE and SIGSYS -- they are handled by synchronous exceptions
|
|
|
|
** triggered by errno returns.
|
|
|
|
*/
|
|
|
|
new.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGPIPE, &new, 0);
|
|
|
|
#ifdef SIGSYS
|
|
|
|
sigaction(SIGSYS, &new, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sneak me the S48 interrupt handlers vector. */
|
1999-09-15 20:20:37 -04:00
|
|
|
s48_value get_int_handlers(void)
|
1999-09-14 09:32:05 -04:00
|
|
|
{
|
1999-09-23 10:36:25 -04:00
|
|
|
fprintf(stderr,"get_int_handlers return 1 instead of Sinterrupt_handlersS ");
|
1999-09-15 20:20:37 -04:00
|
|
|
//return Sinterrupt_handlersS;
|
|
|
|
return 1;
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|