r82019 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82018‎ | r82019 | r82020 >
Date:16:22, 12 February 2011
Author:platonides
Status:ok
Tags:
Comment:
Follow up r82015. Add support for logging by tcp.
open_logging_file() bits taken from php_fsockopen_stream at ext/standard/fsock.c
The else branch should work for more things than tcp, like unix. Note however that
although it should work with udp, the messages aren't actually sent properly and also that
calling php_stream_xport_create() with something without a protocol, will default to tcp.
Modified paths:
  • /trunk/php/wmerrors/wmerrors.c (modified) (history)

Diff [purge]

Index: trunk/php/wmerrors/wmerrors.c
@@ -9,6 +9,7 @@
1010 #include "php_wmerrors.h"
1111 #include "php_streams.h" /* for __php_stream_call_depth */
1212 #include "SAPI.h" /* for sapi_module */
 13+#include "ext/standard/file.h" /* for file_globals aka. FG() */
1314 #include "ext/date/php_date.h" /* for php_format_date */
1415 #include "ext/standard/php_smart_str.h" /* for smart_str */
1516 #include "ext/standard/html.h" /* for php_escape_html_entities */
@@ -121,7 +122,6 @@
122123 * it's not enabled,
123124 * OR the error is not one of E_{,CORE_,COMPILE_,USER_,RECOVERABLE_}ERROR,
124125 * OR the error is an E_RECOVERABLE_ERROR and is being thrown as an exception,
125 - * OR our SAPI is not apache
126126 * OR it's triggering itself (recursion guard)
127127 */
128128 if ( !WMERRORS_G(enabled)
@@ -137,6 +137,7 @@
138138 /* No more OOM errors for now thanks */
139139 zend_set_memory_limit((size_t)-1);
140140
 141+ /* Do not show the html error to console */
141142 if ( WMERRORS_G(enabled) && strncmp(sapi_module.name, "cli", 3) ) {
142143 /* Show the message */
143144 wmerrors_show_message(type, error_filename, error_lineno, format, args TSRMLS_CC);
@@ -154,6 +155,29 @@
155156 old_error_cb(type, error_filename, error_lineno, format, args);
156157 }
157158
 159+static php_stream * open_logging_file(const char* stream_name) {
 160+ php_stream * stream;
 161+ int err; char *errstr = NULL;
 162+ struct timeval tv;
 163+
 164+ if ( strncmp( stream_name, "tcp://", 6 ) ) {
 165+ /* Is it a wrapper? */
 166+ stream = php_stream_open_wrapper(stream_name, "ab", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL);
 167+ } else {
 168+ /* Maybe it's a transport? */
 169+ double timeout = FG(default_socket_timeout);
 170+ unsigned long conv;
 171+ conv = (unsigned long) (timeout * 1000000.0);
 172+ tv.tv_sec = conv / 1000000;
 173+ tv.tv_usec = conv % 1000000;
 174+
 175+ stream = php_stream_xport_create(stream_name, strlen(stream_name), ENFORCE_SAFE_MODE | REPORT_ERRORS,
 176+ STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, &tv, NULL, &errstr, &err);
 177+ }
 178+
 179+ return stream;
 180+}
 181+
158182 /* Callback for zend_print_zval_r_ex()
159183 * Gets the file to write from the module global logfile_stream.
160184 */
@@ -177,7 +201,7 @@
178202 }
179203
180204 /* Try opening the logging file */
181 - WMERRORS_G(logfile_stream) = php_stream_open_wrapper(WMERRORS_G(logging_file), "ab", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL);
 205+ WMERRORS_G(logfile_stream) = open_logging_file( WMERRORS_G(logging_file) );
182206 if ( !WMERRORS_G(logfile_stream) ) {
183207 return;
184208 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82015Removed some leaks (internal to the request)....platonides14:49, 12 February 2011

Status & tagging log