diff options
author | Grzegorz Nosek <root@localdomain.pl> | 2015-04-19 11:04:13 +0200 |
---|---|---|
committer | Grzegorz Nosek <root@localdomain.pl> | 2015-04-19 11:04:13 +0200 |
commit | deabe97f2108edb5715dfc4ab4609514bf3d8157 (patch) | |
tree | 886920296e41a1e8910b3eb13fefb7ba76960d99 | |
parent | b6696a1495dc818d0b22d9c2e9be7c618e25b3af (diff) | |
parent | 5ad97b1c7eb853a921e0167e6bfcb6b1815b4fa4 (diff) | |
download | fcgiwrap-deabe97f2108edb5715dfc4ab4609514bf3d8157.tar.xz fcgiwrap-deabe97f2108edb5715dfc4ab4609514bf3d8157.zip |
Merge remote-tracking branch 'stromnet/socket_cleanup'
Fixes: https://github.com/gnosek/fcgiwrap/pull/26
-rw-r--r-- | fcgiwrap.c | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -605,14 +605,29 @@ err_pipein: FCGI_puts("System error"); } +static volatile sig_atomic_t sigint_received ; +static void sigint_handler(int __attribute__((__unused__))dummy) +{ + sigint_received = 1; + FCGX_ShutdownPending(); // Or we could send SIGUSR1 +} + static void fcgiwrap_main(void) { + struct sigaction a; signal(SIGCHLD, SIG_IGN); signal(SIGPIPE, SIG_IGN); + // Use sigaction for SIGINT so we can avoid SA_RESTART and actually react + a.sa_handler = sigint_handler; + a.sa_flags = 0; + sigemptyset( &a.sa_mask ); + sigaction( SIGINT, &a, NULL ); + sigaction( SIGTERM, &a, NULL ); + inherited_environ = environ; - while (FCGI_Accept() >= 0) { + while (FCGI_Accept() >= 0 && !sigint_received) { handle_fcgi_request(); } } @@ -689,7 +704,7 @@ static int listen_on_fd(int fd) { return 0; } -static int setup_socket(char *url) { +static int setup_socket(char *url, int *fd_out) { char *p = url; char *q; int fd; @@ -769,6 +784,7 @@ invalid_url: return -1; } + *fd_out = fd; return listen_on_fd(fd); } @@ -776,6 +792,7 @@ int main(int argc, char **argv) { int nchildren = 1; char *socket_url = NULL; + int fd = 0; int c; while ((c = getopt(argc, argv, "c:hfs:p:")) != -1) { @@ -833,13 +850,25 @@ int main(int argc, char **argv) } else #endif if (socket_url) { - if (setup_socket(socket_url) < 0) { + if (setup_socket(socket_url, &fd) < 0) { return 1; } - free(socket_url); } prefork(nchildren); fcgiwrap_main(); + + if(fd) { + const char *p = socket_url; + close(fd); + + if(socket_url) { + if (!strncmp(p, "unix:", sizeof("unix:") - 1)) { + p += sizeof("unix:") - 1; + unlink(p); + } + free(socket_url); + } + } return 0; } |