1151497Sru/* Copyright (C) 1992, 2001, 2003, 2004 Free Software Foundation, Inc. 275584Sru Written by James Clark (jjc@jclark.com) 375584Sru 475584SruThis file is part of groff. 575584Sru 675584Srugroff is free software; you can redistribute it and/or modify it under 775584Sruthe terms of the GNU General Public License as published by the Free 875584SruSoftware Foundation; either version 2, or (at your option) any later 975584Sruversion. 1075584Sru 1175584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 1275584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 1375584SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1475584Srufor more details. 1575584Sru 1675584SruYou should have received a copy of the GNU General Public License along 1775584Sruwith groff; see the file COPYING. If not, write to the Free Software 18151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 1975584Sru 2075584Sru/* Unfortunately vendors seem to have problems writing a <signal.h> 2175584Sruthat is correct for C++, so we implement all signal handling in C. */ 2275584Sru 23151497Sru#include <stdlib.h> 24151497Sru 25104862Sru#ifdef HAVE_CONFIG_H 26104862Sru#include <config.h> 27104862Sru#endif 28104862Sru 2975584Sru#include <sys/types.h> 3075584Sru#include <signal.h> 3175584Sru#ifdef HAVE_UNISTD_H 3275584Sru#include <unistd.h> 3375584Sru#endif 3475584Sru 35151497Sru#ifdef __cplusplus 36151497Sruextern "C" { 3775584Sru#endif 3875584Sru 39151497Sruextern void cleanup(void); 4075584Sru 41151497Srustatic RETSIGTYPE handle_fatal_signal(int signum) 4275584Sru{ 4375584Sru signal(signum, SIG_DFL); 4475584Sru cleanup(); 45151497Sru#ifdef HAVE_KILL 4675584Sru kill(getpid(), signum); 47151497Sru#else 48151497Sru /* MS-DOS and Win32 don't have kill(); the best compromise is 49151497Sru probably to use exit() instead. */ 50151497Sru exit(signum); 51151497Sru#endif 5275584Sru} 5375584Sru 54151497Sruvoid catch_fatal_signals(void) 5575584Sru{ 5675584Sru#ifdef SIGHUP 5775584Sru signal(SIGHUP, handle_fatal_signal); 5875584Sru#endif 5975584Sru signal(SIGINT, handle_fatal_signal); 6075584Sru signal(SIGTERM, handle_fatal_signal); 6175584Sru} 6275584Sru 63151497Sru#ifdef __cplusplus 64151497Sru} 65151497Sru#endif 66151497Sru 6775584Sru#ifndef HAVE_RENAME 6875584Sru 6975584Sruvoid ignore_fatal_signals() 7075584Sru{ 7175584Sru#ifdef SIGHUP 7275584Sru signal(SIGHUP, SIG_IGN); 7375584Sru#endif 7475584Sru signal(SIGINT, SIG_IGN); 7575584Sru signal(SIGTERM, SIG_IGN); 7675584Sru} 7775584Sru 7875584Sru#endif /* not HAVE_RENAME */ 79