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