signal.c revision 104862
1279377Simp/* Copyright (C) 1992, 2001 Free Software Foundation, Inc.
2279377Simp     Written by James Clark (jjc@jclark.com)
3279377Simp
4295436SandrewThis file is part of groff.
5279377Simp
6279377Simpgroff is free software; you can redistribute it and/or modify it under
7279377Simpthe terms of the GNU General Public License as published by the Free
8279377SimpSoftware Foundation; either version 2, or (at your option) any later
9279377Simpversion.
10279377Simp
11279377Simpgroff is distributed in the hope that it will be useful, but WITHOUT ANY
12279377SimpWARRANTY; without even the implied warranty of MERCHANTABILITY or
13279377SimpFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14279377Simpfor more details.
15279377Simp
16279377SimpYou should have received a copy of the GNU General Public License along
17279377Simpwith groff; see the file COPYING.  If not, write to the Free Software
18279377SimpFoundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19279377Simp
20279377Simp/* Unfortunately vendors seem to have problems writing a <signal.h>
21279377Simpthat is correct for C++, so we implement all signal handling in C. */
22279377Simp
23279377Simp#ifdef HAVE_CONFIG_H
24279377Simp#include <config.h>
25279377Simp#endif
26279377Simp
27279377Simp#include <sys/types.h>
28279377Simp#include <signal.h>
29279377Simp#ifdef HAVE_UNISTD_H
30279377Simp#include <unistd.h>
31279377Simp#endif
32279377Simp
33279377Simp#ifndef RETSIGTYPE
34279377Simp#define RETSIGTYPE void
35279377Simp#endif
36279377Simp
37279377Simpextern void cleanup();
38279377Simp
39279377Simpstatic RETSIGTYPE handle_fatal_signal(signum)
40279377Simp     int signum;
41279377Simp{
42279377Simp  signal(signum, SIG_DFL);
43279377Simp  cleanup();
44279377Simp  kill(getpid(), signum);
45279377Simp}
46279377Simp
47279377Simpvoid catch_fatal_signals()
48279377Simp{
49279377Simp#ifdef SIGHUP
50279377Simp  signal(SIGHUP, handle_fatal_signal);
51279377Simp#endif
52279377Simp  signal(SIGINT, handle_fatal_signal);
53279377Simp  signal(SIGTERM, handle_fatal_signal);
54279377Simp}
55279377Simp
56279377Simp#ifndef HAVE_RENAME
57279377Simp
58279377Simpvoid ignore_fatal_signals()
59279377Simp{
60279377Simp#ifdef SIGHUP
61279377Simp  signal(SIGHUP, SIG_IGN);
62279377Simp#endif
63279377Simp  signal(SIGINT, SIG_IGN);
64279377Simp  signal(SIGTERM, SIG_IGN);
65279377Simp}
66279377Simp
67279377Simp#endif /* not HAVE_RENAME */
68279377Simp