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