Hi.
I'm writing a FCGI-app and have come to a problem. I want to handle SIGINT to take down the server under control. But when handling SIGINT the accept-call doesn't get interrupted, so I have to refresh the browser to get use of the socket and then it closes.
I'm not directly familiar with signals. I obviously got it all wrong. Maybe it doesn't work as I think it does?
It's multithreaded and the main process set the signal handler
Code:
static void _signal_handler(int signum) {
switch (signum) {
case SIGINT:
srv_logmsg(_srv, LOG_INFO, "Server shutdown received");
FCGX_ShutdownPending();
break;
}
}
with
Code:
struct sigaction a;
a.sa_handler = _signal_handler;
a.sa_flags = 0;
sigemptyset(&a.sa_mask);
sigaction(SIGINT, &a, NULL);
I'm using libfcgi as you can see. All threads are created into:
Code:
static void* _thread_start(void* p) {
struct req req;
struct srv* srv = (struct srv*) p;
req_init(&req, srv);
while (!srv->shutdown) {
pthread_mutex_lock(&srv->mux_accept);
if (!(srv->shutdown = FCGX_Accept_r(&req.fcgi))) {
pthread_mutex_unlock(&srv->mux_accept);
req_setup(&req, srv);
FCGX_PutS("Status: 200 Ok\r\nContent-type: text/html\r\n\r\n"
"Ok!", req.fcgi.out);
req_reset(&req);
} else {
pthread_mutex_unlock(&srv->mux_accept);
break;
}
}
req_cleanup(&req);
}
And the main thread also enter that, after all threads are created.
FCGX_Requests are created with...
Code:
FCGX_InitRequest(&req->fcgi, srv->fcgi_socket, FCGI_FAIL_ACCEPT_ON_INTR);
The interrupt on accept() works if I don't handle the interrupt my self, (but then we've don't get a clean shutdown either).