summaryrefslogtreecommitdiff
path: root/fcgiwrap.c
diff options
context:
space:
mode:
Diffstat (limited to 'fcgiwrap.c')
-rw-r--r--fcgiwrap.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/fcgiwrap.c b/fcgiwrap.c
index 458b6d4..b44d8aa 100644
--- a/fcgiwrap.c
+++ b/fcgiwrap.c
@@ -613,14 +613,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();
}
}
@@ -777,13 +792,18 @@ invalid_url:
return -1;
}
- return listen_on_fd(fd);
+ if (listen_on_fd(fd) < 0) {
+ return -1;
+ }
+
+ return fd;
}
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) {
@@ -841,13 +861,25 @@ int main(int argc, char **argv)
} else
#endif
if (socket_url) {
- if (setup_socket(socket_url) < 0) {
+ fd = setup_socket(socket_url);
+ if (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);
+ }
+ }
+ }
return 0;
}