rsc | fd04aac | 2003-11-23 18:12:54 +0000 | [diff] [blame^] | 1 | #include <signal.h> |
| 2 | |
| 3 | #include <u.h> |
| 4 | #define NOPLAN9DEFINES |
| 5 | #include <libc.h> |
| 6 | #include "9proc.h" |
| 7 | |
| 8 | extern char *_p9sigstr(int, char*); |
| 9 | |
| 10 | static int sigs[] = { |
| 11 | SIGHUP, |
| 12 | SIGINT, |
| 13 | SIGQUIT, |
| 14 | SIGILL, |
| 15 | SIGTRAP, |
| 16 | SIGABRT, |
| 17 | SIGEMT, |
| 18 | SIGFPE, |
| 19 | SIGBUS, |
| 20 | SIGSEGV, |
| 21 | SIGSYS, |
| 22 | SIGPIPE, |
| 23 | SIGALRM, |
| 24 | SIGTERM, |
| 25 | SIGTSTP, |
| 26 | SIGTTIN, |
| 27 | SIGTTOU, |
| 28 | SIGXCPU, |
| 29 | SIGXFSZ, |
| 30 | SIGVTALRM, |
| 31 | SIGUSR1, |
| 32 | SIGUSR2, |
| 33 | }; |
| 34 | |
| 35 | static void (*notifyf)(void*, char*); |
| 36 | |
| 37 | static void |
| 38 | notifysigf(int sig) |
| 39 | { |
| 40 | int v; |
| 41 | char tmp[64]; |
| 42 | Uproc *up; |
| 43 | |
| 44 | up = _p9uproc(); |
| 45 | v = p9setjmp(up->notejb); |
| 46 | if(v == 0 && notifyf) |
| 47 | (*notifyf)(nil, _p9sigstr(sig, tmp)); |
| 48 | else if(v == 2){ |
| 49 | if(0)print("HANDLED %d\n", sig); |
| 50 | return; |
| 51 | } |
| 52 | if(0)print("DEFAULT %d\n", sig); |
| 53 | signal(sig, SIG_DFL); |
| 54 | kill(getpid(), sig); |
| 55 | } |
| 56 | |
| 57 | int |
| 58 | notify(void (*f)(void*, char*)) |
| 59 | { |
| 60 | int i; |
| 61 | void (*sf)(int); |
| 62 | |
| 63 | if(f == nil) |
| 64 | sf = SIG_DFL; |
| 65 | else{ |
| 66 | notifyf = f; |
| 67 | sf = notifysigf; |
| 68 | } |
| 69 | for(i=0; i<nelem(sigs); i++) |
| 70 | signal(sigs[i], sf); |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | int |
| 75 | noted(int v) |
| 76 | { |
| 77 | Uproc *up; |
| 78 | |
| 79 | up = _p9uproc(); |
| 80 | p9longjmp(up->notejb, v==NCONT ? 2 : 1); |
| 81 | abort(); |
| 82 | return 0; |
| 83 | } |