summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING22
-rw-r--r--README.rst7
-rw-r--r--fcgiwrap.c40
3 files changed, 65 insertions, 4 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..99c77fd
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,22 @@
+Copyright (c) 2007-2013 Grzegorz Nosek
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.rst b/README.rst
index 4686c34..5d7a30e 100644
--- a/README.rst
+++ b/README.rst
@@ -10,6 +10,11 @@ fcgiwrap
This page has been translated into `Spanish <http://www.webhostinghub.com/support/es/misc/fcgiwrap>`_ language by Maria Ramos from `Webhostinghub.com/support/edu <http://www.webhostinghub.com/support/edu>`_.
+License
+=======
+
+This software is released under the MIT license. See COPYING for details.
+
Features
========
- very lightweight (84KB of private memory per instance)
@@ -25,6 +30,8 @@ requirements
------------
``Makefile`` and ``configure`` script is generated by GNU *autotools*. Therefore you need the latter.
+``pkg-config`` is needed, else you may get AC_DEFINE errors.
+
``fcgiwrap`` links to *dev-libs/fcgi* which can be obtained from http://www.fastcgi.com/ .
``fcgiwrap`` also uses (but not requires) ``systemd`` for socket activation.
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;
}