00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "signal.h"
00023
00024 void set_signal_handlers(void)
00025 {
00026 DEBUG2("set_signal_handlers: start; i_am = %d", i_am)
00027 struct sigaction sa;
00028 sa.sa_handler = catch_signal;
00029 sigemptyset(&sa.sa_mask);
00030 sa.sa_flags =0;
00031 if (!sigaction(SIGHUP, &sa, NULL) == -1) DIE("Couldn't set a trap for SIGHUP")
00032 if (!sigaction(SIGTERM, &sa, NULL) == -1) DIE("Couldn't set a trap for SIGTERM")
00033 DEBUG2("set_signal_handlers: end; i_am = %d", i_am)
00034 }
00035
00036
00037
00038 void catch_signal(int sig)
00039 {
00040 DEBUG3("catch_signal: i_am = %d; sig = %d", i_am, sig)
00041 unlink(lockfile);
00042 if (sig == SIGTERM)
00043 {
00044 if (i_am == I_AM_CHILD)
00045 DEBUG1("Child ends after a SIGTERM.")
00046 else
00047 DEBUG1("Granchild ends after a SIGTERM.")
00048 _exit(15);
00049 }
00050 }