1 /* "Larn is copyrighted 1986 by Noah Morgan.\n" */
6 static void s2choose(void);
7 static void cntlc(int);
10 static void tstop(int);
12 static void sigill(int);
13 static void sigtrap(int);
14 static void sigiot(int);
15 static void sigemt(int);
16 static void sigfpe(int);
17 static void sigbus(int);
18 static void sigsegv(int);
19 static void sigsys(int);
20 static void sigpipe(int);
21 static void sigterm(int);
22 static void sigpanic(int);
24 #define BIT(a) (1<<((a)-1))
27 s2choose(void) /* text to be displayed if ^C during intro screen */
34 lprcat(" to continue: ");
39 cntlc(__unused int sig) /* what to do for a ^C */
41 if (nosignal) /* don't do anything if inhibited */
43 signal(SIGQUIT, SIG_IGN);
44 signal(SIGINT, SIG_IGN);
51 signal(SIGQUIT, cntlc);
52 signal(SIGINT, cntlc);
56 * subroutine to save the game if a hangup signal
59 sgam(__unused int sig)
61 savegame(savefilename);
63 died(-257); /* hangup signal */
68 tstop(__unused int sig) /* control Y */
70 if (nosignal) /* nothing if inhibited */
75 signal(SIGTSTP, SIG_DFL);
77 /* looks like BSD4.2 or higher - must clr mask for signal to take effect*/
78 sigsetmask(sigblock(0) & ~BIT(SIGTSTP));
80 kill(getpid(), SIGTSTP);
83 signal(SIGTSTP, tstop);
94 * subroutine to issue the needed signal traps called from main()
97 sigill(__unused int sig)
103 sigtrap(__unused int sig)
109 sigiot(__unused int sig)
115 sigemt(__unused int sig)
121 sigfpe(__unused int sig)
127 sigbus(__unused int sig)
133 sigsegv(__unused int sig)
139 sigsys(__unused int sig)
145 sigpipe(__unused int sig)
151 sigterm(__unused int sig)
159 signal(SIGQUIT, cntlc);
160 signal(SIGINT, cntlc);
161 signal(SIGKILL, SIG_IGN);
162 signal(SIGHUP, sgam);
163 signal(SIGILL, sigill);
164 signal(SIGTRAP, sigtrap);
165 signal(SIGIOT, sigiot);
166 signal(SIGEMT, sigemt);
167 signal(SIGFPE, sigfpe);
168 signal(SIGBUS, sigbus);
169 signal(SIGSEGV, sigsegv);
170 signal(SIGSYS, sigsys);
171 signal(SIGPIPE, sigpipe);
172 signal(SIGTERM, sigterm);
174 signal(SIGTSTP, tstop);
175 signal(SIGSTOP, tstop);
179 static const char *signame[NSIG] = { "",
180 "SIGHUP", /* 1 hangup */
181 "SIGINT", /* 2 interrupt */
182 "SIGQUIT", /* 3 quit */
183 "SIGILL", /* 4 illegal instruction (not reset when caught) */
184 "SIGTRAP", /* 5 trace trap (not reset when caught) */
185 "SIGIOT", /* 6 IOT instruction */
186 "SIGEMT", /* 7 EMT instruction */
187 "SIGFPE", /* 8 floating point exception */
188 "SIGKILL", /* 9 kill (cannot be caught or ignored) */
189 "SIGBUS", /* 10 bus error */
190 "SIGSEGV", /* 11 segmentation violation */
191 "SIGSYS", /* 12 bad argument to system call */
192 "SIGPIPE", /* 13 write on a pipe with no one to read it */
193 "SIGALRM", /* 14 alarm clock */
194 "SIGTERM", /* 15 software termination signal from kill */
195 "SIGURG", /* 16 urgent condition on IO channel */
196 "SIGSTOP", /* 17 sendable stop signal not from tty */
197 "SIGTSTP", /* 18 stop signal from tty */
198 "SIGCONT", /* 19 continue a stopped process */
199 "SIGCHLD", /* 20 to parent on child stop or exit */
200 "SIGTTIN", /* 21 to readers pgrp upon background tty read */
201 "SIGTTOU", /* 22 like TTIN for output if (tp->t_local<OSTOP) */
202 "SIGIO", /* 23 input/output possible signal */
203 "SIGXCPU", /* 24 exceeded CPU time limit */
204 "SIGXFSZ", /* 25 exceeded file size limit */
205 "SIGVTALRM",/* 26 virtual time alarm */
206 "SIGPROF", /* 27 profiling time alarm */
207 "SIGWINCH",/* 28 window size changes */
208 "SIGINFO", /* 29 information request */
209 "SIGUSR1", /* 30 user defined signal 1 */
210 "SIGUSR2", /* 31 user defined signal 2 */
214 * routine to process a fatal error signal
220 signal(sig, SIG_DFL);
221 sprintf(buf, "\nLarn - Panic! Signal %d received [%s]", sig, signame[sig]);
222 write(2, buf, strlen(buf));
225 savegame(savefilename);
226 kill(getpid(), sig); /* this will terminate us */