Blob
1 #include <signal.h>3 #include <u.h>4 #define NOPLAN9DEFINES5 #include <libc.h>6 #include "9proc.h"8 extern char *_p9sigstr(int, char*);10 static struct {11 int sig;12 int restart;13 } sigs[] = {14 SIGHUP, 0,15 SIGINT, 0,16 SIGQUIT, 0,17 SIGILL, 0,18 SIGTRAP, 0,19 /* SIGABRT, */20 #ifdef SIGEMT21 SIGEMT, 0,22 #endif23 SIGFPE, 0,24 SIGBUS, 0,25 /* SIGSEGV, */26 SIGCHLD, 1,27 SIGSYS, 0,28 SIGPIPE, 0,29 SIGALRM, 0,30 SIGTERM, 0,31 SIGTSTP, 1,32 SIGTTIN, 1,33 SIGTTOU, 1,34 SIGXCPU, 0,35 SIGXFSZ, 0,36 SIGVTALRM, 0,37 SIGUSR1, 0,38 SIGUSR2, 0,39 #ifdef SIGINFO40 SIGINFO, 0,41 #endif42 };44 static void (*notifyf)(void*, char*);46 static void47 notifysigf(int sig)48 {49 int v;50 char tmp[64];51 Uproc *up;53 up = _p9uproc();54 v = p9setjmp(up->notejb);55 if(v == 0 && notifyf)56 (*notifyf)(nil, _p9sigstr(sig, tmp));57 else if(v == 2){58 if(0)print("HANDLED %d\n", sig);59 return;60 }61 if(0)print("DEFAULT %d\n", sig);62 signal(sig, SIG_DFL);63 kill(getpid(), sig);64 }66 int67 notify(void (*f)(void*, char*))68 {69 int i;70 struct sigaction sa;72 memset(&sa, 0, sizeof sa);73 if(f == nil)74 sa.sa_handler = SIG_DFL;75 else{76 notifyf = f;77 sa.sa_handler = notifysigf;78 }79 for(i=0; i<nelem(sigs); i++){80 if(sigs[i].restart)81 sa.sa_flags |= SA_RESTART;82 else83 sa.sa_flags &= ~SA_RESTART;84 sigaction(sigs[i].sig, &sa, 0);85 }86 return 0;87 }89 int90 noted(int v)91 {92 Uproc *up;94 up = _p9uproc();95 p9longjmp(up->notejb, v==NCONT ? 2 : 1);96 abort();97 return 0;98 }