mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Stop closing stderr and stdout streams (#8569)
Extensions may (and do) write to stderr in mshutdown and similar. In the best case, with the stderr stream closed, it's just swallowed. However, some libraries will do things like try to detect color, and these will outright fail and cause an error path to be taken.
This commit is contained in:
parent
33850fbb15
commit
fa78e17724
4 changed files with 31 additions and 6 deletions
|
@ -539,6 +539,14 @@ static void cli_register_file_handles(void) /* {{{ */
|
|||
s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out);
|
||||
s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err);
|
||||
|
||||
/* Release stream resources, but don't free the underlying handles. Othewrise,
|
||||
* extensions which write to stderr or company during mshutdown/gshutdown
|
||||
* won't have the expected functionality.
|
||||
*/
|
||||
if (s_in) s_in->flags |= PHP_STREAM_FLAG_NO_CLOSE;
|
||||
if (s_out) s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE;
|
||||
if (s_err) s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;
|
||||
|
||||
if (s_in==NULL || s_out==NULL || s_err==NULL) {
|
||||
if (s_in) php_stream_close(s_in);
|
||||
if (s_out) php_stream_close(s_out);
|
||||
|
@ -546,12 +554,6 @@ static void cli_register_file_handles(void) /* {{{ */
|
|||
return;
|
||||
}
|
||||
|
||||
#if PHP_DEBUG
|
||||
/* do not close stdout and stderr */
|
||||
s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE;
|
||||
s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;
|
||||
#endif
|
||||
|
||||
s_in_process = s_in;
|
||||
|
||||
php_stream_to_zval(s_in, &ic.value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue