1 /* $NetBSD: signal.c,v 1.7 2001/02/05 00:57:34 christos Exp $ */
3 /* "Larn is copyrighted 1986 by Noah Morgan.\n" */
7 __RCSID("$NetBSD: signal.c,v 1.7 2001/02/05 00:57:34 christos Exp $");
17 static void s2choose(void);
18 static void cntlc(int);
19 static void sgam(int);
20 static void tstop(int);
21 static void sigpanic(int);
23 #define BIT(a) (1<<((a)-1))
27 { /* text to be displayed if ^C during intro
34 lprcat(" to continue: ");
41 { /* what to do for a ^C */
43 return; /* don't do anything if inhibited */
44 signal(SIGQUIT
, SIG_IGN
);
45 signal(SIGINT
, SIG_IGN
);
52 signal(SIGQUIT
, cntlc
);
53 signal(SIGINT
, cntlc
);
57 * subroutine to save the game if a hangup signal
63 savegame(savefilename
);
65 died(-257); /* hangup signal */
74 return; /* nothing if inhibited */
78 signal(SIGTSTP
, SIG_DFL
);
81 * looks like BSD4.2 or higher - must clr mask for signal to take
84 sigsetmask(sigblock(0) & ~BIT(SIGTSTP
));
86 kill(getpid(), SIGTSTP
);
89 signal(SIGTSTP
, tstop
);
100 * subroutine to issue the needed signal traps called from main()
105 signal(SIGQUIT
, cntlc
);
106 signal(SIGINT
, cntlc
);
107 signal(SIGKILL
, SIG_IGN
);
108 signal(SIGHUP
, sgam
);
109 signal(SIGILL
, sigpanic
);
110 signal(SIGTRAP
, sigpanic
);
111 signal(SIGIOT
, sigpanic
);
112 signal(SIGEMT
, sigpanic
);
113 signal(SIGFPE
, sigpanic
);
114 signal(SIGBUS
, sigpanic
);
115 signal(SIGSEGV
, sigpanic
);
116 signal(SIGSYS
, sigpanic
);
117 signal(SIGPIPE
, sigpanic
);
118 signal(SIGTERM
, sigpanic
);
120 signal(SIGTSTP
, tstop
);
121 signal(SIGSTOP
, tstop
);
126 * routine to process a fatal error signal
133 signal(sig
, SIG_DFL
);
134 snprintf(buf
, sizeof(buf
),
135 "\nLarn - Panic! Signal %d received [SIG%s]", sig
,
137 write(2, buf
, strlen(buf
));
140 savegame(savefilename
);
141 kill(getpid(), sig
); /* this will terminate us */