|
@@ -14,6 +14,16 @@ static void clean_exit(int status)
|
14
|
14
|
pid_t pyfcgi_spawn_monitor()
|
15
|
15
|
{
|
16
|
16
|
pid_t res;
|
|
17
|
+ struct sigaction act;
|
|
18
|
+ const int signums[] = {SIGINT, SIGTERM, SIGALRM, 0};
|
|
19
|
+ const int *signum;
|
|
20
|
+ int err;
|
|
21
|
+
|
|
22
|
+ signum = signums;
|
|
23
|
+ act.sa_handler = pyfcgi_monitor_sighandler;
|
|
24
|
+ sigemptyset(&act.sa_mask);
|
|
25
|
+ act.sa_flags = 0;
|
|
26
|
+ act.sa_restorer = NULL;
|
17
|
27
|
|
18
|
28
|
if(!PyFCGI_conf.mon_socket)
|
19
|
29
|
{
|
|
@@ -33,6 +43,17 @@ pid_t pyfcgi_spawn_monitor()
|
33
|
43
|
if(!res)
|
34
|
44
|
{ //child process
|
35
|
45
|
pyfcgi_logger_set_ident("StatServ");
|
|
46
|
+ while(*signum)
|
|
47
|
+ {
|
|
48
|
+ if(sigaction(*signum, &act, NULL))
|
|
49
|
+ {
|
|
50
|
+ err = errno;
|
|
51
|
+ pyfcgi_log(LOG_ERR, "Unable to run sigaction for %s : %s",
|
|
52
|
+ strsignal(*signum), strerror(err));
|
|
53
|
+ exit(PYFCGI_FATAL);
|
|
54
|
+ }
|
|
55
|
+ signum++;
|
|
56
|
+ }
|
36
|
57
|
pyfcgi_monitor_loop();
|
37
|
58
|
pyfcgi_log(LOG_ALERT, "Monitor loop should never return but just did it...");
|
38
|
59
|
clean_exit(PYFCGI_FATAL);
|
|
@@ -331,3 +352,10 @@ free_err:
|
331
|
352
|
return -1;
|
332
|
353
|
}
|
333
|
354
|
|
|
355
|
+void pyfcgi_monitor_sighandler(int signum)
|
|
356
|
+{
|
|
357
|
+ pyfcgi_log(LOG_NOTICE, "Received signal %s, exiting",
|
|
358
|
+ strsignal(signum));
|
|
359
|
+ clean_exit(0);
|
|
360
|
+}
|
|
361
|
+
|