-->

FastCGI cleanup code does not work under windows

2019-07-27 15:30发布

问题:

Using apache on a windows server with mod_fastcgi, the C code looks like that:

void main() {
    init();
    while (FCGI_Accept() >= 0)
        work();
    cleanup();
}

When the service is taken down (i.e.: net stop apache2), the process terminates without getting to the cleanup code.

What am I missing here?

回答1:

It seems, from reading the FCGI_Accept manpage and this FAQ entry that FCGI_Accept does not, in fact, return -1 in the case of Apache shutting down. Try setting a signal handler for SIGUSR1 and SIGTERM. There's an example (not Windows-specific, but it's worth a try) posted a while ago on a mailing list, here.



回答2:

The only way to exit prematurely would be to call "exit()" somewhere inside work() (or FCGI_Accept()...)

Edit:

If you think it might be FCGI_Accept(), try using onexit() to set up a callback to be called from "exit()". At the very least this will confirm that "exit()" was called prematurely.