Blame


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