r82027 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82026‎ | r82027 | r82028 >
Date:20:23, 12 February 2011
Author:catrope
Status:deferred (Comments)
Tags:
Comment:
Add option to ignore errors in the course of writing to the log file. This is useful e.g. when writing to a UDP port with no listener, which throws an E_NOTICE
Modified paths:
  • /trunk/php/wmerrors/php_wmerrors.h (modified) (history)
  • /trunk/php/wmerrors/wmerrors.c (modified) (history)

Diff [purge]

Index: trunk/php/wmerrors/wmerrors.c
@@ -53,6 +53,7 @@
5454 STD_PHP_INI_ENTRY("wmerrors.message_file", "", PHP_INI_ALL, OnUpdateString, message_file, zend_wmerrors_globals, wmerrors_globals)
5555 STD_PHP_INI_ENTRY("wmerrors.logging_file", "", PHP_INI_ALL, OnUpdateString, logging_file, zend_wmerrors_globals, wmerrors_globals)
5656 STD_PHP_INI_ENTRY("wmerrors.log_level", "0", PHP_INI_ALL, OnUpdateLong, log_level, zend_wmerrors_globals, wmerrors_globals)
 57+ STD_PHP_INI_BOOLEAN("wmerrors.ignore_logging_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_logging_errors, zend_wmerrors_globals, wmerrors_globals)
5758 PHP_INI_END()
5859
5960 void (*old_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
@@ -131,7 +132,11 @@
132133 && type != E_USER_ERROR && type != E_RECOVERABLE_ERROR)
133134 || WMERRORS_G(recursion_guard))
134135 {
135 - old_error_cb(type, error_filename, error_lineno, format, args);
 136+ /* recursion_guard != 1 means this is an error in writing to the log file.
 137+ * Ignore it if configured to do so.
 138+ */
 139+ if (WMERRORS_G(recursion_guard) == 1 || !WMERRORS_G(ignore_logging_errors))
 140+ old_error_cb(type, error_filename, error_lineno, format, args);
136141 return;
137142 }
138143 WMERRORS_G(recursion_guard) = 1;
@@ -160,10 +165,14 @@
161166 php_stream * stream;
162167 int err; char *errstr = NULL;
163168 struct timeval tv;
 169+ int flags = ENFORCE_SAFE_MODE;
164170
 171+ if (!WMERRORS_G(ignore_logging_errors))
 172+ flags |= REPORT_ERRORS;
 173+
165174 if ( strncmp( stream_name, "tcp://", 6 ) && strncmp( stream_name, "udp://", 6 ) ) {
166175 /* Is it a wrapper? */
167 - stream = php_stream_open_wrapper(stream_name, "ab", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL);
 176+ stream = php_stream_open_wrapper(stream_name, "ab", flags, NULL);
168177 } else {
169178 /* Maybe it's a transport? */
170179 double timeout = FG(default_socket_timeout);
@@ -172,7 +181,7 @@
173182 tv.tv_sec = conv / 1000000;
174183 tv.tv_usec = conv % 1000000;
175184
176 - stream = php_stream_xport_create(stream_name, strlen(stream_name), ENFORCE_SAFE_MODE | REPORT_ERRORS,
 185+ stream = php_stream_xport_create(stream_name, strlen(stream_name), flags,
177186 STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, &tv, NULL, &errstr, &err);
178187 }
179188
@@ -204,7 +213,10 @@
205214 }
206215
207216 /* Try opening the logging file */
 217+ /* Set recursion_guard==2 whenever we're doing something to the log file */
 218+ WMERRORS_G(recursion_guard) = 2;
208219 logfile_stream = open_logging_file( WMERRORS_G(logging_file) );
 220+ WMERRORS_G(recursion_guard) = 1;
209221 if ( !logfile_stream ) {
210222 return;
211223 }
@@ -226,7 +238,10 @@
227239 zend_fetch_debug_backtrace(trace, 0, 0 TSRMLS_CC);
228240 zend_print_zval_r_ex(wmerrors_write_trace, trace, 4 TSRMLS_CC);
229241 FREE_ZVAL(trace);
 242+
 243+ WMERRORS_G(recursion_guard) = 2;
230244 php_stream_write(logfile_stream, WMERRORS_G(log_buffer).c, WMERRORS_G(log_buffer).len TSRMLS_CC);
 245+ WMERRORS_G(recursion_guard) = 1;
231246 }
232247
233248 php_stream_close( logfile_stream );
Index: trunk/php/wmerrors/php_wmerrors.h
@@ -29,6 +29,7 @@
3030 int recursion_guard;
3131 int enabled;
3232 long int log_level;
 33+ int ignore_logging_errors;
3334 smart_str log_buffer;
3435 ZEND_END_MODULE_GLOBALS(wmerrors)
3536

Comments

#Comment by Platonides (talk | contribs)   21:21, 12 February 2011

Isn't the lack of REPORT_ERRORS flags enough?

#Comment by Catrope (talk | contribs)   11:26, 13 February 2011

You'd think so, but this is PHP :)

My guess is that REPORT_ERRORS only suppresses errors in the course of opening the file or stream, not while doing other things with it. The write function doesn't check for the flag, and the UDP "connection refused" error is thrown on write, not on open.

Status & tagging log