1 static char Sccsid[] = "@(#)setsig.c	1.3	12/22/88";
2 
3 # include	"signal.h"
4 #undef NSIG
5 # ifdef PWB
6 #define NSIG 16
7 # else
8 #define NSIG 4
9 # endif
10 # include	"../hdr/macros.h"
11 #include <sys/syscall.h>
12 #define	syswrite(a,b,c)	syscall(SYS_write,a,b,c)
13 
14 /*
15 	General-purpose signal setting routine.
16 	All non-ignored, non-caught signals are caught.
17 	If a signal other than hangup, interrupt, or quit is caught,
18 	a "user-oriented" message is printed on file descriptor 2 with
19 	a number for help(I).
20 	If hangup, interrupt or quit is caught, that signal
21 	is set to ignore.
22 	Termination is like that of "fatal",
23 	via "clean_up(sig)" (sig is the signal number)
24 	and "exit(userexit(1))".
25 
26 	If the file "dump.core" exists in the current directory
27 	the function commits
28 	suicide to produce a core dump
29 	(after calling clean_up, but before calling userexit).
30 */
31 
32 
33 char	*Mesg[NSIG] = {
34 	0,
35 	0,	/* Hangup */
36 	0,	/* Interrupt */
37 	0,	/* Quit */
38 # ifdef PWB
39 	"Illegal instruction",
40 	"Trace/BPT trap",
41 	"IOT trap",
42 	"EMT trap",
43 	"Floating exception",
44 	"Killed",
45 	"Bus error",
46 	"Memory fault",
47 	"Bad system call",
48 	"Broken pipe",
49 	"Alarm clock",
50 	"Terminated"
51 # endif PWB
52 };
53 
54 
55 setsig()
56 {
57 	extern int setsig1();
58 	register int j, n;
59 
60 	for (j=1; j<NSIG; j++)
61 		if (n=signal(j,setsig1))
62 			signal(j,n);
63 }
64 
65 
66 static char preface[] = "SIGNAL: ";
67 static char endmsg[] = " (ut12)\n";
68 
69 setsig1(sig)
70 int sig;
71 {
72 # ifndef PWB
73 	sig = 2;
74 # endif PWB
75 	if (Mesg[sig]) {
76 		syswrite(2,preface,length(preface));
77 		syswrite(2,Mesg[sig],length(Mesg[sig]));
78 		syswrite(2,endmsg,length(endmsg));
79 	}
80 	else
81 		signal(sig,1);
82 	clean_up(sig);
83 	if(open("dump.core",0) > 0) {
84 		signal(SIGIOT,0);
85 		abort();
86 	}
87 	exit(userexit(1));
88 }
89