com php-src: - Fixed bug #61045 (fpm don't send error log to fastcgi clients): NEWS sapi/fpm/fpm/fpm_main.c sapi/fpm/fpm/zlog .c sapi/fpm/fpm/zlog.h
| From: | Jérôme Loyet | Date: | Tue, 22 May 2012 06:34:27 +0000 |
| Subject: | com php-src: - Fixed bug #61045 (fpm don't send error log to fastcgi clients): NEWS sapi/fpm/fpm/fpm_main.c sapi/fpm/fpm/zlog .c sapi/fpm/fpm/zlog.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-69131@lists.php.net to get a copy of this message | ||
Commit: faca4e08b4dffbf00b1bc20fc5d4e310b3f99c13
Author: Jerome Loyet <fat@php.net> Tue, 22 May 2012 08:34:27 +0200
Parents: c973fef48d6302b9bcec898de8e39d8d7e23adef
Branches: PHP-5.3
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=faca4e08b4dffbf00b1bc20fc5d4e310b3f99c13
Log:
- Fixed bug #61045 (fpm don't send error log to fastcgi clients)
Bugs:
https://bugs.php.net/61045
Changed paths:
M NEWS
M sapi/fpm/fpm/fpm_main.c
M sapi/fpm/fpm/zlog.c
M sapi/fpm/fpm/zlog.h
Diff:
diff --git a/NEWS b/NEWS
index 5f1146a..d6ac422 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ PHP NEWS
?? ??? 2012, PHP 5.3.14
+- FPM
+ . Fixed bug #61045 (fpm don't send error log to fastcgi clients). (fat)
+
- XML Writer:
. Fixed bug #62064 (memory leak in the XML Writer module).
(jean-pierre dot lozi at lip6 dot fr)
diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
index 1ebeefa..5767971 100644
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
@@ -655,14 +655,38 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC)
}
}
-static void sapi_cgi_log_message(char *message)
+/* {{{ sapi_cgi_log_fastcgi
+ *
+ * Ignore level, we want to send all messages through fastcgi
+ */
+void sapi_cgi_log_fastcgi(int level, char *message, size_t len)
{
TSRMLS_FETCH();
- if (CGIG(fcgi_logging)) {
- zlog(ZLOG_NOTICE, "PHP message: %s", message);
+ fcgi_request *request = (fcgi_request*) SG(server_context);
+
+ /* ensure we want:
+ * - to log (fastcgi.logging in php.ini)
+ * - we are currently dealing with a request
+ * - the message is not empty
+ */
+ if (CGIG(fcgi_logging) && request && message && len > 0) {
+ char *buf = malloc(len + 2);
+ memcpy(buf, message, len);
+ memcpy(buf + len, "\n", sizeof("\n"));
+ fcgi_write(request, FCGI_STDERR, buf, len+1);
+ free(buf);
}
}
+/* }}} */
+
+/* {{{ sapi_cgi_log_message
+ */
+static void sapi_cgi_log_message(char *message)
+{
+ zlog(ZLOG_NOTICE, "PHP message: %s", message);
+}
+/* }}} */
/* {{{ php_cgi_ini_activate_user_config
*/
@@ -1778,6 +1802,9 @@ consult the installation file that came with this distribution, or visit \n\
fcgi_fd = fpm_run(&max_requests);
parent = 0;
+ /* onced forked tell zlog to also send messages through sapi_cgi_log_fastcgi() */
+ zlog_set_external_logger(sapi_cgi_log_fastcgi);
+
/* make php call us to get _ENV vars */
php_php_import_environment_variables = php_import_environment_variables;
php_import_environment_variables = cgi_php_import_environment_variables;
diff --git a/sapi/fpm/fpm/zlog.c b/sapi/fpm/fpm/zlog.c
index b127ec1..80db9d8 100644
--- a/sapi/fpm/fpm/zlog.c
+++ b/sapi/fpm/fpm/zlog.c
@@ -22,6 +22,7 @@
static int zlog_fd = -1;
static int zlog_level = ZLOG_NOTICE;
static int launched = 0;
+static void (*external_logger)(int, char *, size_t) = NULL;
static const char *level_names[] = {
[ZLOG_DEBUG] = "DEBUG",
@@ -41,6 +42,12 @@ const int syslog_priorities[] = {
};
#endif
+void zlog_set_external_logger(void (*logger)(int, char *, size_t)) /* {{{ */
+{
+ external_logger = logger;
+}
+/* }}} */
+
const char *zlog_get_level_name(int log_level) /* {{{ */
{
if (log_level < 0) {
@@ -101,6 +108,19 @@ void zlog_ex(const char *function, int line, int flags, const char *fmt, ...)
/*
int truncated = 0;
int saved_errno;
+ if (external_logger) {
+ va_start(args, fmt);
+ len = vsnprintf(buf, buf_size, fmt, args);
+ va_end(args);
+ if (len >= buf_size) {
+ memcpy(buf + buf_size - sizeof("..."), "...", sizeof("...") - 1);
+ len = buf_size - 1;
+ }
+ external_logger(flags & ZLOG_LEVEL_MASK, buf, len);
+ len = 0;
+ memset(buf, '\0', buf_size);
+ }
+
if ((flags & ZLOG_LEVEL_MASK) < zlog_level) {
return;
}
diff --git a/sapi/fpm/fpm/zlog.h b/sapi/fpm/fpm/zlog.h
index e6a5c01..1945922 100644
--- a/sapi/fpm/fpm/zlog.h
+++ b/sapi/fpm/fpm/zlog.h
@@ -9,6 +9,7 @@
struct timeval;
+void zlog_set_external_logger(void (*logger)(int, char *, size_t));
int zlog_set_fd(int new_fd);
int zlog_set_level(int new_value);
const char *zlog_get_level_name(int log_level);