From 1fac94ee495edb1bf2f618b7e1dbc2ff51251411 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Sun, 1 Dec 2013 10:04:14 -0500 Subject: [PATCH 1/3] This fixes a problem found with php-cgi.exe on Windows; it wouldn't terminate when httpd was stopped. The root cause was: * PHP doesn't respond to the termination event set by mod_fastcgi (this is a feature of the FastCGI programming library provided by the mod_fastcgi folks, which PHP apparently does not use). * The Windows code was broken in that it wouldn't forcibly kill after sleeping if it had previously tried to set the termination event, due to confusionf about state (modified by the patch). Even if the child_wait thread was running, it wouldn't have changed the state from VICTIM. Hmmm... Before trying to fix it I couldn't find anything useful with a web search but after arriving at a solution I found the same one here: http://mailman.fastcgi.com/pipermail/fastcgi-developers/2009-October/000365.html --- fcgi_pm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fcgi_pm.c b/fcgi_pm.c index 08fd33d..7f97c02 100644 --- a/fcgi_pm.c +++ b/fcgi_pm.c @@ -201,7 +201,8 @@ static void shutdown_all() /* Send KILL to all processes */ for (i = 0; i < numChildren; i++, proc++) { - if (proc->state == FCGI_RUNNING_STATE) + if (proc->state == FCGI_RUNNING_STATE + || proc->state == FCGI_VICTIM_STATE) { fcgi_kill(proc, SIGKILL); } From 0bfca4955891ad63c82df0c8fc232861402da22d Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Sun, 1 Dec 2013 10:37:27 -0500 Subject: [PATCH 2/3] Fix module log ids for all of mod_fastcgi. With the previous patch, the module id ("fastcgi") was only available for messages logged from mod_fastcgi.c. For messages logged from other files, the id would be unavailable for logging *and* module-specific log levels would not take affect. Part of the original patch has been removed -- the use of AP_DECLARE_MODULE(fastcgi) -- because it wasn't sufficient for providing a module id when logging from source files other than that one, and it interfered with the real fix (APLOG_USE_MODULE). --- .../byte-compile-against-apache24.diff | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/debian/patches/byte-compile-against-apache24.diff b/debian/patches/byte-compile-against-apache24.diff index 417c03e..581e037 100644 --- a/debian/patches/byte-compile-against-apache24.diff +++ b/debian/patches/byte-compile-against-apache24.diff @@ -1,19 +1,23 @@ Index: libapache-mod-fastcgi/fcgi.h =================================================================== ---- libapache-mod-fastcgi.orig/fcgi.h 2012-03-07 14:29:04.005720240 +0100 -+++ libapache-mod-fastcgi/fcgi.h 2012-03-07 14:29:07.830566657 +0100 -@@ -34,6 +34,10 @@ +--- libapache-mod-fastcgi.orig/fcgi.h 2008-09-22 06:36:06.000000000 -0400 ++++ libapache-mod-fastcgi/fcgi.h 2013-12-01 10:17:42.480086695 -0500 +@@ -34,6 +34,14 @@ #define APACHE2 #endif +#ifdef AP_DECLARE_MODULE +#define APACHE24 +#endif ++ ++#ifdef APLOG_USE_MODULE ++APLOG_USE_MODULE(fastcgi); ++#endif + #ifdef APACHE2 #include -@@ -57,10 +61,16 @@ +@@ -57,10 +65,16 @@ #define XtOffsetOf APR_OFFSETOF #define ap_select select @@ -30,7 +34,7 @@ Index: libapache-mod-fastcgi/fcgi.h #ifndef S_ISDIR #define S_ISDIR(m) (((m)&(S_IFMT)) == (S_IFDIR)) -@@ -365,42 +375,42 @@ +@@ -354,42 +368,42 @@ #ifdef APACHE2 #ifdef WIN32 @@ -110,8 +114,8 @@ Index: libapache-mod-fastcgi/fcgi.h Index: libapache-mod-fastcgi/mod_fastcgi.c =================================================================== ---- libapache-mod-fastcgi.orig/mod_fastcgi.c 2012-03-07 14:29:04.017047773 +0100 -+++ libapache-mod-fastcgi/mod_fastcgi.c 2012-03-07 14:29:07.841272721 +0100 +--- libapache-mod-fastcgi.orig/mod_fastcgi.c 2008-11-09 09:31:03.000000000 -0500 ++++ libapache-mod-fastcgi/mod_fastcgi.c 2013-12-01 10:16:51.472085611 -0500 @@ -97,6 +97,10 @@ } while (0) #endif @@ -123,15 +127,3 @@ Index: libapache-mod-fastcgi/mod_fastcgi.c /* * Global variables */ -@@ -3014,7 +3018,11 @@ - ap_hook_fixups(fixups, NULL, NULL, APR_HOOK_MIDDLE); - } - -+#ifdef APACHE24 -+AP_DECLARE_MODULE(fastcgi) = -+#else - module AP_MODULE_DECLARE_DATA fastcgi_module = -+#endif - { - STANDARD20_MODULE_STUFF, - fcgi_config_create_dir_config, /* per-directory config creator */ From 5772005c4d437253e4d3ed525fd9e95c6007a585 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Sun, 1 Dec 2013 11:24:03 -0500 Subject: [PATCH 3/3] Close listen sockets in the process manager. --- mod_fastcgi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mod_fastcgi.c b/mod_fastcgi.c index 67a70aa..cf0747b 100644 --- a/mod_fastcgi.c +++ b/mod_fastcgi.c @@ -341,6 +341,7 @@ static apcb_t init_module(server_rec *s, pool *p) if (rv == APR_INCHILD) { /* child */ + ap_close_listeners(); fcgi_pm_main(NULL); exit(1); }