blob: 095a3f5413d96ad561bf548c4f52717cfb7a0a4d [file] [log] [blame]
rscfd04aac2003-11-23 18:12:54 +00001#include <signal.h>
2
3#include <u.h>
4#define NOPLAN9DEFINES
5#include <libc.h>
6#include "9proc.h"
7
8extern char *_p9sigstr(int, char*);
9
10static 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
35static void (*notifyf)(void*, char*);
36
37static void
38notifysigf(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){
49if(0)print("HANDLED %d\n", sig);
50 return;
51 }
52if(0)print("DEFAULT %d\n", sig);
53 signal(sig, SIG_DFL);
54 kill(getpid(), sig);
55}
56
57int
58notify(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
74int
75noted(int v)
76{
77 Uproc *up;
78
79 up = _p9uproc();
80 p9longjmp(up->notejb, v==NCONT ? 2 : 1);
81 abort();
82 return 0;
83}