scsh-0.6/scsh/jcontrol1.c

98 lines
2.3 KiB
C

/* This code is all obsolete & should be thrown away. 8/23/96 Olin. */
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include "cstuff.h"
extern int errno;
/* Hack the blocked-signal mask.
*******************************************************************************
*/
#include "machine/sigset.h"
int set_procmask(int hi, int lo, int *old_lo_p)
{
sigset_t mask, old_mask;
int old_hi;
make_sigset(&mask, hi, lo);
sigprocmask(SIG_SETMASK, &mask, &old_mask);
split_sigset(old_mask, &old_hi, old_lo_p);
return old_hi;
}
int get_procmask(int *old_lo_p)
{
sigset_t old_mask;
int old_hi;
sigprocmask(SIG_SETMASK, NULL, &old_mask);
split_sigset(old_mask, &old_hi, old_lo_p);
return old_hi;
}
/* Set/Get signal handlers
*******************************************************************************
*/
long int pending_signals = 0;
void scm_handle_sig(int sig) {pending_signals |= (1<<sig);}
s48_value set_int_handler(int sig, s48_value handler, int flags,
s48_value *ohandler, int *oflags)
{
struct sigaction new, old;
sigemptyset(&new.sa_mask); /* WTF */
new.sa_flags = flags;
if( handler == S48_FALSE ) new.sa_handler = SIG_IGN;
else if( handler == S48_TRUE ) new.sa_handler = SIG_DFL;
else {
new.sa_handler = scm_handle_sig;
/* Do other stuff. */
}
if( sigaction(sig, &new, &old) ) {
*ohandler = S48_FALSE;
return s48_enter_fixnum(errno);
}
*oflags = old.sa_flags;
/* if( old.sa_handler == SIG_IGN ) *ohandler = S48_FALSE;
else if( old.sa_handler == SIG_DFL ) *ohandler = S48_TRUE;
else if( old.sa_handler == scm_handle_sig ) {
*ohandler = s48_enter_fixnum(0); /* Fix later. */
}
else *ohandler = s48_enter_fixnum(-1); /* Unknown signal handler. */
return S48_FALSE;
}
s48_value get_int_handler(int signal, s48_value *handler, int *flags)
{
struct sigaction old;
if( sigaction(signal, NULL, &old) ) {
*handler = S48_FALSE;
return s48_enter_fixnum(errno);
}
*flags = old.sa_flags;
if( old.sa_handler == SIG_IGN ) *handler = S48_FALSE;
else if( old.sa_handler == SIG_DFL ) *handler = S48_TRUE;
else if( old.sa_handler == scm_handle_sig ) {
*handler = s48_enter_fixnum(0); /* Fix later. */
}
else *handler = s48_enter_fixnum(-1); /* Unknown signal handler. */
return S48_FALSE;
}