|
@@ -4,6 +4,7 @@ static pyfcgi_monitor_t pyfcgi_mon;
|
4
|
4
|
|
5
|
5
|
static void clean_exit(int status)
|
6
|
6
|
{
|
|
7
|
+ pyfcgi_wd_stop();
|
7
|
8
|
if(pyfcgi_mon.sockserv)
|
8
|
9
|
{
|
9
|
10
|
if(pyfcgi_mon.sockcli)
|
|
@@ -38,8 +39,12 @@ pid_t pyfcgi_spawn_monitor()
|
38
|
39
|
{
|
39
|
40
|
pid_t res;
|
40
|
41
|
struct sigaction act, actdrop;
|
|
42
|
+ struct timespec wd_delay;
|
41
|
43
|
int err;
|
42
|
44
|
|
|
45
|
+ wd_delay.tv_sec = 0;
|
|
46
|
+ wd_delay.tv_nsec = 250000000; //0.25s
|
|
47
|
+
|
43
|
48
|
act.sa_handler = pyfcgi_monitor_sighandler;
|
44
|
49
|
sigemptyset(&act.sa_mask);
|
45
|
50
|
act.sa_flags = 0;
|
|
@@ -85,6 +90,15 @@ pid_t pyfcgi_spawn_monitor()
|
85
|
90
|
pyfcgi_log(LOG_WARNING, "Unable to restore ALARM sigaction : %s",
|
86
|
91
|
strerror(errno));
|
87
|
92
|
}
|
|
93
|
+
|
|
94
|
+ if(pyfcgi_wd_init(pyfcgi_monitor_timeout, &wd_delay) < 0)
|
|
95
|
+ {
|
|
96
|
+ pyfcgi_log(LOG_ALERT,
|
|
97
|
+ "Unable to start watchdog, sleep 1s then exiting...");
|
|
98
|
+ sleep(1);
|
|
99
|
+ exit(PYFCGI_FATAL);
|
|
100
|
+ }
|
|
101
|
+
|
88
|
102
|
pyfcgi_monitor_loop();
|
89
|
103
|
pyfcgi_log(LOG_ALERT, "Monitor loop should never return but just did it...");
|
90
|
104
|
clean_exit(PYFCGI_FATAL);
|
|
@@ -208,6 +222,7 @@ void pyfcgi_monitor_stream_loop(pyfcgi_monitor_addr_t addr_serv)
|
208
|
222
|
{
|
209
|
223
|
sockcli = pyfcgi_mon.sockcli = accept(pyfcgi_mon.sockserv,
|
210
|
224
|
(struct sockaddr*)&cliaddr, &addrlen);
|
|
225
|
+ pyfcgi_wd_arm(); //watchdog
|
211
|
226
|
if(sockcli < 0)
|
212
|
227
|
{
|
213
|
228
|
err = errno;
|
|
@@ -243,6 +258,7 @@ void pyfcgi_monitor_stream_loop(pyfcgi_monitor_addr_t addr_serv)
|
243
|
258
|
}
|
244
|
259
|
shutdown(sockcli, SHUT_RDWR);
|
245
|
260
|
close(sockcli);
|
|
261
|
+ pyfcgi_wd_pause(); //watchdog
|
246
|
262
|
pyfcgi_mon.sockcli = 0;
|
247
|
263
|
|
248
|
264
|
addrlen = sizeof(cliaddr);
|
|
@@ -451,3 +467,9 @@ void pyfcgi_monitor_sighandler(int signum)
|
451
|
467
|
clean_exit(0);
|
452
|
468
|
}
|
453
|
469
|
|
|
470
|
+void pyfcgi_monitor_timeout(int signum)
|
|
471
|
+{
|
|
472
|
+ pyfcgi_log(LOG_ALERT, "Monitor server timeout, killed by watchdog");
|
|
473
|
+ clean_exit(PYFCGI_TIMEOUT);
|
|
474
|
+}
|
|
475
|
+
|