2003-11-23 18:12:54 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
|
|
#include <u.h>
|
|
|
|
|
#define NOPLAN9DEFINES
|
|
|
|
|
#include <libc.h>
|
|
|
|
|
#include "9proc.h"
|
|
|
|
|
|
|
|
|
|
extern char *_p9sigstr(int, char*);
|
|
|
|
|
|
|
|
|
|
static int sigs[] = {
|
|
|
|
|
SIGHUP,
|
|
|
|
|
SIGINT,
|
|
|
|
|
SIGQUIT,
|
|
|
|
|
SIGILL,
|
|
|
|
|
SIGTRAP,
|
2003-12-03 22:50:48 +00:00
|
|
|
/* SIGABRT, */
|
2003-11-24 00:43:41 +00:00
|
|
|
#ifdef SIGEMT
|
2003-11-23 18:12:54 +00:00
|
|
|
SIGEMT,
|
2003-11-24 00:43:41 +00:00
|
|
|
#endif
|
2003-11-23 18:12:54 +00:00
|
|
|
SIGFPE,
|
|
|
|
|
SIGBUS,
|
2003-12-11 17:48:38 +00:00
|
|
|
/* SIGSEGV, */
|
2003-11-23 18:12:54 +00:00
|
|
|
SIGSYS,
|
|
|
|
|
SIGPIPE,
|
|
|
|
|
SIGALRM,
|
|
|
|
|
SIGTERM,
|
|
|
|
|
SIGTSTP,
|
|
|
|
|
SIGTTIN,
|
|
|
|
|
SIGTTOU,
|
|
|
|
|
SIGXCPU,
|
|
|
|
|
SIGXFSZ,
|
|
|
|
|
SIGVTALRM,
|
|
|
|
|
SIGUSR1,
|
|
|
|
|
SIGUSR2,
|
2003-11-24 00:43:41 +00:00
|
|
|
#ifdef SIGINFO
|
|
|
|
|
SIGINFO,
|
|
|
|
|
#endif
|
2003-11-23 18:12:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void (*notifyf)(void*, char*);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
notifysigf(int sig)
|
|
|
|
|
{
|
|
|
|
|
int v;
|
|
|
|
|
char tmp[64];
|
|
|
|
|
Uproc *up;
|
|
|
|
|
|
|
|
|
|
up = _p9uproc();
|
|
|
|
|
v = p9setjmp(up->notejb);
|
|
|
|
|
if(v == 0 && notifyf)
|
|
|
|
|
(*notifyf)(nil, _p9sigstr(sig, tmp));
|
|
|
|
|
else if(v == 2){
|
|
|
|
|
if(0)print("HANDLED %d\n", sig);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(0)print("DEFAULT %d\n", sig);
|
|
|
|
|
signal(sig, SIG_DFL);
|
|
|
|
|
kill(getpid(), sig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
notify(void (*f)(void*, char*))
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2003-12-03 22:50:48 +00:00
|
|
|
struct sigaction sa;
|
2003-11-23 18:12:54 +00:00
|
|
|
|
2003-12-03 22:50:48 +00:00
|
|
|
memset(&sa, 0, sizeof sa);
|
2003-11-23 18:12:54 +00:00
|
|
|
if(f == nil)
|
2003-12-03 22:50:48 +00:00
|
|
|
sa.sa_handler = SIG_DFL;
|
2003-11-23 18:12:54 +00:00
|
|
|
else{
|
|
|
|
|
notifyf = f;
|
2003-12-03 22:50:48 +00:00
|
|
|
sa.sa_handler = notifysigf;
|
2003-11-23 18:12:54 +00:00
|
|
|
}
|
|
|
|
|
for(i=0; i<nelem(sigs); i++)
|
2003-12-03 22:50:48 +00:00
|
|
|
sigaction(sigs[i], &sa, 0);
|
2003-11-23 18:12:54 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
noted(int v)
|
|
|
|
|
{
|
|
|
|
|
Uproc *up;
|
|
|
|
|
|
|
|
|
|
up = _p9uproc();
|
|
|
|
|
p9longjmp(up->notejb, v==NCONT ? 2 : 1);
|
|
|
|
|
abort();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|