00001 /*************************************************************************** 00002 signal_handler.c 00003 ------------------- 00004 begin : Thu Dec 6 2001 00005 copyright : (C) 2001-2002 by Christian Hoenig & Gunter Ohrner 00006 email : pdepp@CustomCDROM.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00024 #include "common.h" 00025 00026 #include <signal.h> 00027 00028 #include "signal_handler.h" 00029 00030 #include "server.h" 00031 00032 00034 void sgnlSigInt(int id) 00035 { 00036 caught_signal = id; 00037 //running is a global variable, wich keeps the main loop running, here we stop it 00038 running = false; 00039 } 00040 00042 void sgnlSigHup(int id) 00043 { 00044 caught_signal = id; 00045 //running is a global variable, wich keeps the main loop running, here we stop it 00046 running = false; 00047 } 00048 00050 void sgnlSigTerm(int id) 00051 { 00052 caught_signal = id; 00053 //running is a global variable, wich keeps the main loop running, here we stop it 00054 running = false; 00055 } 00056 00058 void sgnlSigUsr1(int id) 00059 { 00060 caught_signal = id; 00061 ; 00062 } 00063 00064 #ifndef NDEBUG 00065 00066 void sgnlSigRecord(int id) 00067 { 00068 caught_signal = id; 00069 } 00070 #else 00071 00072 # define sgnlSigRecord SIG_IGN 00073 #endif 00074 00075 00076 00077 //initializes the signalhandler 00078 void sgnlInit() 00079 { 00080 /* #ifndef NDEBUG 00081 int i; 00082 00083 for(i = 1; i < 36; ++i) 00084 { 00085 signal( i , sgnlSigRecord ); 00086 } 00087 #endif */ 00088 00089 caught_signal = 0; 00090 00091 00092 //define the signalhandler for the different signals 00093 signal( SIGINT , sgnlSigInt ); 00094 signal( SIGHUP , sgnlSigHup ); 00095 signal( SIGTERM , sgnlSigTerm ); 00096 //for logfile shuffling 00097 signal( SIGUSR1 , sgnlSigUsr1 ); 00098 00099 //I ignore those signals: 00100 signal( SIGPIPE , sgnlSigRecord ); 00101 signal( SIGUSR2 , sgnlSigRecord ); 00102 } 00103