]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/signal.c
1 /* $NetBSD: signal.c,v 1.6 1997/10/18 20:03:50 christos Exp $ */
3 /* "Larn is copyrighted 1986 by Noah Morgan.\n" */
7 __RCSID("$NetBSD: signal.c,v 1.6 1997/10/18 20:03:50 christos Exp $");
17 static void s2choose
__P((void));
18 static void cntlc
__P((int));
19 static void sgam
__P((int));
20 static void tstop
__P((int));
21 static void sigpanic
__P((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 sprintf(buf
, "\nLarn - Panic! Signal %d received [SIG%s]", sig
, sys_signame
[sig
]);
135 write(2, buf
, strlen(buf
));
138 savegame(savefilename
);
139 kill(getpid(), sig
); /* this will terminate us */