]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/signal.c
1 /* $NetBSD: signal.c,v 1.9 2012/06/19 05:30:44 dholland Exp $ */
3 /* "Larn is copyrighted 1986 by Noah Morgan.\n" */
7 __RCSID("$NetBSD: signal.c,v 1.9 2012/06/19 05:30:44 dholland 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: ");
40 { /* what to do for a ^C */
42 return; /* 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
61 savegame(savefilename
);
63 died(-257); /* hangup signal */
71 return; /* nothing if inhibited */
75 signal(SIGTSTP
, SIG_DFL
);
78 * looks like BSD4.2 or higher - must clr mask for signal to take
81 sigsetmask(sigblock(0) & ~BIT(SIGTSTP
));
83 kill(getpid(), SIGTSTP
);
86 signal(SIGTSTP
, tstop
);
97 * subroutine to issue the needed signal traps called from main()
102 signal(SIGQUIT
, cntlc
);
103 signal(SIGINT
, cntlc
);
104 signal(SIGKILL
, SIG_IGN
);
105 signal(SIGHUP
, sgam
);
106 signal(SIGILL
, sigpanic
);
107 signal(SIGTRAP
, sigpanic
);
108 signal(SIGIOT
, sigpanic
);
109 signal(SIGEMT
, sigpanic
);
110 signal(SIGFPE
, sigpanic
);
111 signal(SIGBUS
, sigpanic
);
112 signal(SIGSEGV
, sigpanic
);
113 signal(SIGSYS
, sigpanic
);
114 signal(SIGPIPE
, sigpanic
);
115 signal(SIGTERM
, sigpanic
);
117 signal(SIGTSTP
, tstop
);
118 signal(SIGSTOP
, tstop
);
123 * routine to process a fatal error signal
129 signal(sig
, SIG_DFL
);
130 snprintf(buf
, sizeof(buf
),
131 "\nLarn - Panic! Signal %d received [SIG%s]", sig
,
133 write(2, buf
, strlen(buf
));
136 savegame(savefilename
);
137 kill(getpid(), sig
); /* this will terminate us */