1 
2 /*
3 	VoIPong Voice Over IP Sniffer
4 	Copyright (C) 2004 Murat Balaban <murat || enderunix.org>
5 	All rights reserved.
6 
7 	This program is free software; you can redistribute it and/or
8 	modify it under the terms of the GNU General Public License
9 	as published by the Free Software Foundation; either version 2
10 	of the License, or (at your option) any later version.
11 
12 	This program is distributed in the hope that it will be useful,
13 	but WITHOUT ANY WARRANTY; without even the implied warranty of
14 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 	GNU General Public License for more details.
16 
17 	You should have received a copy of the GNU General Public License
18 	along with this program; if not, write to the Free Software
19 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21 
22 
23 #include <signal.h>
24 #include <string.h>
25 #include <errno.h>
26 
27 
28 #include <voipong.h>
29 #include <miscutil.h>
30 #include <voipongsign.h>
31 #include <voipongworker.h>
32 
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <sys/wait.h>
36 
37 extern void wexit(int);
38 extern int gmainprocess;
39 
40 void
sigint_handler()41 sigint_handler()
42 {
43 	misc_debug(0, "INTERRUPT signal caught, starting shutdown procedures...\n");
44 	wexit(0);
45 }
46 
47 
sigusr2_handler()48 void sigusr2_handler()
49 {
50 }
51 
52 void
sigalrm_handler()53 sigalrm_handler()
54 {
55 }
56 
57 void
sigterm_handler()58 sigterm_handler()
59 {
60 	misc_debug(0, "SHUTDOWN signal caught, starting shutdown procedures...\n");
61 	graceful_shutdown();
62 	wexit(0);
63 }
64 
65 
66 void
sigworkeralrm_handler()67 sigworkeralrm_handler()
68 {
69 }
70 
71 void
sigworkerterm_handler()72 sigworkerterm_handler()
73 {
74 	misc_debug(0, "SHUTDOWN signal caught, starting shutdown procedures...\n");
75 	worker_graceful_exit(0);
76 }
77 
78 
79 
sighandler(int signal)80 void sighandler(int signal)
81 {
82 	switch(signal) {
83 		case SIGCHLD:
84 			process_deadchild();
85 			break;
86 		case SIGINT:
87 			sigterm_handler();
88 			break;
89 		case SIGTERM:
90 			sigterm_handler();
91 			break;
92 		case SIGKILL:
93 			sigterm_handler();
94 			break;
95 		case SIGPIPE:
96 			break;
97 		case SIGALRM:
98 			sigalrm_handler();
99 			break;
100 		case SIGUSR2:
101 			sigusr2_handler();
102 			break;
103 		default:
104 			break;
105 	}
106 }
107 
sigworkerhandler(int signal)108 void sigworkerhandler(int signal)
109 {
110 	switch(signal) {
111 		case SIGINT:
112 		case SIGTERM:
113 			sigworkerterm_handler();
114 			break;
115 		case SIGPIPE:
116 			break;
117 		case SIGALRM:
118 			sigworkeralrm_handler();
119 			break;
120 		default:
121 			break;
122 	}
123 }
124