signal.c revision 75584
175584Sru/* Copyright (C) 1992 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 1875584SruFoundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 2375584Sru#include <sys/types.h> 2475584Sru#include <signal.h> 2575584Sru#ifdef HAVE_UNISTD_H 2675584Sru#include <unistd.h> 2775584Sru#endif 2875584Sru 2975584Sru#ifndef RETSIGTYPE 3075584Sru#define RETSIGTYPE void 3175584Sru#endif 3275584Sru 3375584Sruextern void cleanup(); 3475584Sru 3575584Srustatic RETSIGTYPE handle_fatal_signal(signum) 3675584Sru int signum; 3775584Sru{ 3875584Sru signal(signum, SIG_DFL); 3975584Sru cleanup(); 4075584Sru kill(getpid(), signum); 4175584Sru} 4275584Sru 4375584Sruvoid catch_fatal_signals() 4475584Sru{ 4575584Sru#ifdef SIGHUP 4675584Sru signal(SIGHUP, handle_fatal_signal); 4775584Sru#endif 4875584Sru signal(SIGINT, handle_fatal_signal); 4975584Sru signal(SIGTERM, handle_fatal_signal); 5075584Sru} 5175584Sru 5275584Sru#ifndef HAVE_RENAME 5375584Sru 5475584Sruvoid ignore_fatal_signals() 5575584Sru{ 5675584Sru#ifdef SIGHUP 5775584Sru signal(SIGHUP, SIG_IGN); 5875584Sru#endif 5975584Sru signal(SIGINT, SIG_IGN); 6075584Sru signal(SIGTERM, SIG_IGN); 6175584Sru} 6275584Sru 6375584Sru#endif /* not HAVE_RENAME */ 64