gnosek / fcgiwrap

Simple FastCGI wrapper for CGI scripts
http://nginx.localdomain.pl/
MIT License
407 stars 134 forks source link

Socket cleanup on exit #26

Closed stromnet closed 9 years ago

stromnet commented 10 years ago

When using unix sockets, bind() will fail with "Address already in use" if the file already exists. fcgiwrap did not clean up the socket properly on exit, and we failed to restart.

The FreeBSD ports init script did this cleanup manually when "stop" was executed. However, on system reboot, the initscripts are not called, with the result that manual intervention was required on system boot.

Patch tested and works on FreeBSD 10.0, should be tested on other supported platforms as well, but it's pretty straightforward POSIX signal handling, so it should probably be OK I think.

Note that it will still fail to startup if the machine totally crashes; the alternative would be to unlink the socket before trying to bind, but that comes with other concerns.

gnosek commented 9 years ago

Merged (with a minor tweak), thanks!