1*04ac863bSchristos /*	$NetBSD: signal.c,v 1.1.1.1 2016/01/13 18:41:49 christos Exp $	*/
2*04ac863bSchristos 
3*04ac863bSchristos /* Copyright (C) 1992, 2001, 2003, 2004 Free Software Foundation, Inc.
4*04ac863bSchristos      Written by James Clark (jjc@jclark.com)
5*04ac863bSchristos 
6*04ac863bSchristos This file is part of groff.
7*04ac863bSchristos 
8*04ac863bSchristos groff is free software; you can redistribute it and/or modify it under
9*04ac863bSchristos the terms of the GNU General Public License as published by the Free
10*04ac863bSchristos Software Foundation; either version 2, or (at your option) any later
11*04ac863bSchristos version.
12*04ac863bSchristos 
13*04ac863bSchristos groff is distributed in the hope that it will be useful, but WITHOUT ANY
14*04ac863bSchristos WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*04ac863bSchristos FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16*04ac863bSchristos for more details.
17*04ac863bSchristos 
18*04ac863bSchristos You should have received a copy of the GNU General Public License along
19*04ac863bSchristos with groff; see the file COPYING.  If not, write to the Free Software
20*04ac863bSchristos Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21*04ac863bSchristos 
22*04ac863bSchristos /* Unfortunately vendors seem to have problems writing a <signal.h>
23*04ac863bSchristos that is correct for C++, so we implement all signal handling in C. */
24*04ac863bSchristos 
25*04ac863bSchristos #include <stdlib.h>
26*04ac863bSchristos 
27*04ac863bSchristos #ifdef HAVE_CONFIG_H
28*04ac863bSchristos #include <config.h>
29*04ac863bSchristos #endif
30*04ac863bSchristos 
31*04ac863bSchristos #include <sys/types.h>
32*04ac863bSchristos #include <signal.h>
33*04ac863bSchristos #ifdef HAVE_UNISTD_H
34*04ac863bSchristos #include <unistd.h>
35*04ac863bSchristos #endif
36*04ac863bSchristos 
37*04ac863bSchristos #ifdef __cplusplus
38*04ac863bSchristos extern "C" {
39*04ac863bSchristos #endif
40*04ac863bSchristos 
41*04ac863bSchristos extern void cleanup(void);
42*04ac863bSchristos 
handle_fatal_signal(int signum)43*04ac863bSchristos static RETSIGTYPE handle_fatal_signal(int signum)
44*04ac863bSchristos {
45*04ac863bSchristos   signal(signum, SIG_DFL);
46*04ac863bSchristos   cleanup();
47*04ac863bSchristos #ifdef HAVE_KILL
48*04ac863bSchristos   kill(getpid(), signum);
49*04ac863bSchristos #else
50*04ac863bSchristos   /* MS-DOS and Win32 don't have kill(); the best compromise is
51*04ac863bSchristos      probably to use exit() instead. */
52*04ac863bSchristos   exit(signum);
53*04ac863bSchristos #endif
54*04ac863bSchristos }
55*04ac863bSchristos 
catch_fatal_signals(void)56*04ac863bSchristos void catch_fatal_signals(void)
57*04ac863bSchristos {
58*04ac863bSchristos #ifdef SIGHUP
59*04ac863bSchristos   signal(SIGHUP, handle_fatal_signal);
60*04ac863bSchristos #endif
61*04ac863bSchristos   signal(SIGINT, handle_fatal_signal);
62*04ac863bSchristos   signal(SIGTERM, handle_fatal_signal);
63*04ac863bSchristos }
64*04ac863bSchristos 
65*04ac863bSchristos #ifdef __cplusplus
66*04ac863bSchristos }
67*04ac863bSchristos #endif
68*04ac863bSchristos 
69*04ac863bSchristos #ifndef HAVE_RENAME
70*04ac863bSchristos 
ignore_fatal_signals()71*04ac863bSchristos void ignore_fatal_signals()
72*04ac863bSchristos {
73*04ac863bSchristos #ifdef SIGHUP
74*04ac863bSchristos   signal(SIGHUP, SIG_IGN);
75*04ac863bSchristos #endif
76*04ac863bSchristos   signal(SIGINT, SIG_IGN);
77*04ac863bSchristos   signal(SIGTERM, SIG_IGN);
78*04ac863bSchristos }
79*04ac863bSchristos 
80*04ac863bSchristos #endif /* not HAVE_RENAME */
81