php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #51319
Patch php-apache2-sigblock-20090316.patch.diff revision 2010-09-08 13:32 UTC by hossy421 at yahoo dot co dot jp

Patch php-apache2-sigblock-20090316.patch.diff for Apache related Bug #51319

Patch version 2010-09-08 13:32 UTC

Return to Bug #51319 | Download this patch
Patch Revisions:

Developer: hossy421@yahoo.co.jp

Index: sapi/apache2handler/php_apache.h
===================================================================
RCS file: /repository/php-src/sapi/apache2handler/php_apache.h,v
retrieving revision 1.8.2.1.2.4
diff -u -r1.8.2.1.2.4 php_apache.h
--- sapi/apache2handler/php_apache.h	31 Dec 2008 11:17:48 -0000	1.8.2.1.2.4
+++ sapi/apache2handler/php_apache.h	15 Mar 2009 18:58:42 -0000
@@ -46,6 +46,8 @@
 	int request_processed;
 	/* final content type */
 	char *content_type;
+	volatile apr_uint32_t block_sigs_in_cs;
+	sigset_t old_sig_set;
 } php_struct;
 
 void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf);
Index: sapi/apache2handler/sapi_apache2.c
===================================================================
RCS file: /repository/php-src/sapi/apache2handler/sapi_apache2.c,v
retrieving revision 1.57.2.10.2.19
diff -u -r1.57.2.10.2.19 sapi_apache2.c
--- sapi/apache2handler/sapi_apache2.c	31 Dec 2008 11:17:48 -0000	1.57.2.10.2.19
+++ sapi/apache2handler/sapi_apache2.c	15 Mar 2009 18:58:43 -0000
@@ -50,6 +50,7 @@
 #include "util_script.h"
 #include "http_core.h"
 #include "ap_mpm.h"
+#include "apr_atomic.h"
 
 #include "php_apache.h"
 
@@ -316,6 +317,40 @@
 	return SUCCESS;
 }
 
+static void php_apache2_block_signals()
+{
+#ifndef PHP_WIN32
+	sigset_t ss;
+	php_struct *ctx = SG(server_context);
+
+	if (!ctx || apr_atomic_cas32(&ctx->block_sigs_in_cs, 1, 0)) {
+		return;
+	}
+
+	sigemptyset(&ss);
+	sigaddset(&ss, SIGPROF);
+	sigaddset(&ss, SIGALRM);
+#if defined(ZTS) && defined(PTHREADS)
+	pthread_sigmask(SIG_BLOCK, &ss, &ctx->old_sig_set);
+#else
+	sigprocmask(SIG_BLOCK, &ss, &ctx->old_sig_set);
+#endif
+#endif
+}
+
+static void php_apache2_unblock_signals()
+{
+	php_struct *ctx = SG(server_context);
+	if (!ctx || !apr_atomic_cas32(&ctx->block_sigs_in_cs, 0, 1)) {
+		return;
+	}
+#if defined(ZTS) && defined(PTHREADS)
+	pthread_sigmask(SIG_SETMASK, &ctx->old_sig_set, NULL);
+#else
+	sigprocmask(SIG_SETMASK, &ctx->old_sig_set, NULL);
+#endif
+}
+
 static sapi_module_struct apache2_sapi_module = {
 	"apache2handler",
 	"Apache 2.0 Handler",
@@ -344,7 +379,10 @@
 	php_apache_sapi_log_message,			/* Log message */
 	php_apache_sapi_get_request_time,		/* Request Time */
 
-	STANDARD_SAPI_MODULE_PROPERTIES
+	NULL,                       /* php.ini path override */
+
+	php_apache2_block_signals,
+	php_apache2_unblock_signals
 };
 
 static apr_status_t php_apache_server_shutdown(void *tmp)
@@ -523,6 +561,8 @@
 		 */
 		apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), php_server_context_cleanup, apr_pool_cleanup_null);
 		ctx->r = r;
+		ctx->block_sigs_in_cs = 0;
+		sigemptyset(&ctx->old_sig_set);
 		ctx = NULL; /* May look weird to null it here, but it is to catch the right case in the first_try later on */
 	} else {
 		parent_req = ctx->r;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 07:01:30 2024 UTC