Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31054 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21386 invoked by uid 1010); 18 Jul 2007 15:21:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 21369 invoked from network); 18 Jul 2007 15:21:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2007 15:21:34 -0000 Authentication-Results: pb1.pair.com header.from=jani.taskinen@sci.fi; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jani.taskinen@sci.fi; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sci.fi from 63.208.196.171 cause and error) X-PHP-List-Original-Sender: jani.taskinen@sci.fi X-Host-Fingerprint: 63.208.196.171 outbound.mailhop.org FreeBSD 4.6-4.9 Received: from [63.208.196.171] ([63.208.196.171:2399] helo=outbound.mailhop.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/64-53268-9FF2E964 for ; Wed, 18 Jul 2007 11:21:32 -0400 Received: from [81.22.163.71] (helo=[10.6.109.93]) by outbound.mailhop.org with esmtpsa (SSLv3:RC4-MD5:128) (Exim 4.63) (envelope-from ) id 1IBBLB-000JND-QH for internals@lists.php.net; Wed, 18 Jul 2007 11:21:26 -0400 X-Mail-Handler: MailHop Outbound by DynDNS X-Originating-IP: 81.22.163.71 X-Report-Abuse-To: abuse@dyndns.com (see http://www.mailhop.org/outbound/abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1/Pl41gN6mr3NJFvBy1U2Fmk+ZhLjGKS1Y= Reply-To: jani.taskinen@iki.fi To: internals@lists.php.net Content-Type: multipart/mixed; boundary="=-t39PMRmDeBeGjhbfxcDK" Date: Wed, 18 Jul 2007 18:21:23 +0300 Message-ID: <1184772083.3370.6.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.8.3 (2.8.3-2.fc6) Subject: [PATCH] Allow changing default output for errors to STDERR instead of default STDOUT From: jani.taskinen@sci.fi (Jani Taskinen) --=-t39PMRmDeBeGjhbfxcDK Content-Type: text/plain Content-Transfer-Encoding: 7bit Attached patch (if it comes through, Ins Allah :) overloads the display_errors directive to accept 'stderr' as parameter which makes the errors output to STDERR on CLI/CGI. Applies to PHP_5_2 branch. Default is still STDOUT. --Jani --=-t39PMRmDeBeGjhbfxcDK Content-Disposition: attachment; filename=errors_to_stderr.patch Content-Type: text/x-patch; name=errors_to_stderr.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit Index: main/main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.640.2.23.2.46 diff -u -r1.640.2.23.2.46 main.c --- main/main.c 15 Jul 2007 15:34:28 -0000 1.640.2.23.2.46 +++ main/main.c 18 Jul 2007 15:05:47 -0000 @@ -213,6 +213,84 @@ } /* }}} */ +/* {{{ PHP_INI_MH + */ +static PHP_INI_MH(OnUpdateDisplayErrors) +{ + int mode = 0; + + if (new_value_length == 2 && !strcasecmp("on", new_value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (new_value_length == 3 && !strcasecmp("yes", new_value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (new_value_length == 4 && !strcasecmp("true", new_value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (new_value_length == 6 && !strcasecmp(new_value, "stderr")) { + mode = PHP_DISPLAY_ERRORS_STDERR; + } else if (new_value_length == 6 && !strcasecmp(new_value, "stdout")) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else { + mode = atoi(new_value); + if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } + } + PG(display_errors) = (long) mode; + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_INI_DISP + */ +static PHP_INI_DISP(display_errors_mode) +{ + int mode, tmp_value_len; + char *tmp_value; + + if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { + tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL ); + tmp_value_len = ini_entry->orig_value_length; + } else if (ini_entry->value) { + tmp_value = ini_entry->value; + tmp_value_len = ini_entry->value_length; + } else { + tmp_value = NULL; + tmp_value_len = 0; + } + + if (tmp_value_len == 2 && !strcasecmp("on", tmp_value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (tmp_value_len == 3 && !strcasecmp("yes", tmp_value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (tmp_value_len == 4 && !strcasecmp("true", tmp_value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (tmp_value_len == 6 && !strcasecmp(tmp_value, "stderr")) { + mode = PHP_DISPLAY_ERRORS_STDERR; + } else if (tmp_value_len == 6 && !strcasecmp(tmp_value, "stdout")) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else { + mode = atoi(tmp_value); + if (mode && (mode != PHP_DISPLAY_ERRORS_STDOUT || mode != PHP_DISPLAY_ERRORS_STDERR)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } + } + + switch (mode) { + case PHP_DISPLAY_ERRORS_STDERR: + PUTS("STDERR"); + break; + + case PHP_DISPLAY_ERRORS_STDOUT: + PUTS("STDOUT"); + break; + + default: + PUTS("Off"); + break; + } +} +/* }}} */ + /* Need to convert to strings and make use of: * PHP_SAFE_MODE * @@ -246,7 +324,7 @@ STD_PHP_INI_BOOLEAN("allow_call_time_pass_reference", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, allow_call_time_pass_reference, zend_compiler_globals, compiler_globals) STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals) - STD_PHP_INI_BOOLEAN("display_errors", "1", PHP_INI_ALL, OnUpdateBool, display_errors, php_core_globals, core_globals) + STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode) STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals) @@ -809,7 +887,14 @@ php_printf("%s
\n%s: %s in %s on line %d
\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); } } else { - php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + /* Write CLI/CGI errors to stderr if display_errors = stderr */ + if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) && + PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR + ) { + fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno); + } else { + php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + } } } } Index: main/php_globals.h =================================================================== RCS file: /repository/php-src/main/php_globals.h,v retrieving revision 1.98.2.1.2.6 diff -u -r1.98.2.1.2.6 php_globals.h --- main/php_globals.h 9 Jul 2007 17:27:23 -0000 1.98.2.1.2.6 +++ main/php_globals.h 18 Jul 2007 15:05:47 -0000 @@ -33,7 +33,11 @@ extern ZEND_API struct _php_core_globals core_globals; #endif +/* Error display modes */ +#define PHP_DISPLAY_ERRORS_STDOUT 1 +#define PHP_DISPLAY_ERRORS_STDERR 2 +/* Track vars */ #define TRACK_VARS_POST 0 #define TRACK_VARS_GET 1 #define TRACK_VARS_COOKIE 2 @@ -77,7 +81,7 @@ long max_input_time; zend_bool track_errors; - zend_bool display_errors; + long display_errors; zend_bool display_startup_errors; zend_bool log_errors; long log_errors_max_len; --=-t39PMRmDeBeGjhbfxcDK--