diff options
author | Antony Dovgal <tony2001@php.net> | 2007-02-21 21:57:21 +0000 |
---|---|---|
committer | Antony Dovgal <tony2001@php.net> | 2007-02-21 21:57:21 +0000 |
commit | 4a95928d1dc9c22f2f772c9136581a410efa573c (patch) | |
tree | 3d4ef7e7655d9ee2e357e26c182f07adab2bb70b | |
parent | 2a019a14bf221d71ccea072abec95d5288521ca3 (diff) | |
download | php-git-4a95928d1dc9c22f2f772c9136581a410efa573c.tar.gz |
MFH: implement PHP_STREAM_FLAG_NO_CLOSE and avoid hacks
-rwxr-xr-x | main/php_streams.h | 2 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 9 | ||||
-rwxr-xr-x | main/streams/streams.c | 4 | ||||
-rw-r--r-- | sapi/cli/php_cli.c | 6 |
4 files changed, 12 insertions, 9 deletions
diff --git a/main/php_streams.h b/main/php_streams.h index c7f424f296..e4a56eacab 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -178,6 +178,8 @@ struct _php_stream_wrapper { * might otherwise cause the read to block for much longer than * is strictly required. */ #define PHP_STREAM_FLAG_AVOID_BLOCKING 16 + +#define PHP_STREAM_FLAG_NO_CLOSE 32 struct _php_stream { php_stream_ops *ops; diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 430f789732..365b6c8e5f 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -392,16 +392,7 @@ static int php_stdiop_close(php_stream *stream, int close_handle TSRMLS_DC) data->file = NULL; } } else if (data->fd != -1) { -#if PHP_DEBUG - if ((data->fd == 1 || data->fd == 2) && 0 == strcmp(sapi_module.name, "cli")) { - /* don't close stdout or stderr in CLI in DEBUG mode, as we want to see any leaks */ - ret = 0; - } else { - ret = close(data->fd); - } -#else ret = close(data->fd); -#endif data->fd = -1; } else { return 0; /* everything should be closed already -> success */ diff --git a/main/streams/streams.c b/main/streams/streams.c index 9cd9cce6ef..f132227eaf 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -279,6 +279,10 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0; int release_cast = 1; + if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) { + preserve_handle = 1; + } + #if STREAM_DEBUG fprintf(stderr, "stream_free: %s:%p[%s] in_free=%d opts=%08x\n", stream->ops->label, stream, stream->orig_path, stream->in_free, close_options); #endif diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 71e13f26d0..e7dcef33f3 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -476,6 +476,12 @@ static void cli_register_file_handles(TSRMLS_D) 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); +#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 + if (s_in==NULL || s_out==NULL || s_err==NULL) { FREE_ZVAL(zin); FREE_ZVAL(zout); |