]> granicus.if.org Git - php/commitdiff
implement PHP_STREAM_FLAG_NO_CLOSE and avoid hacks in plain wrapper
authorAntony Dovgal <tony2001@php.net>
Wed, 21 Feb 2007 21:56:45 +0000 (21:56 +0000)
committerAntony Dovgal <tony2001@php.net>
Wed, 21 Feb 2007 21:56:45 +0000 (21:56 +0000)
main/php_streams.h
main/streams/plain_wrapper.c
main/streams/streams.c
sapi/cli/php_cli.c

index fd0060dbac64b6187f6a1061ff3bd27f22a2a585..0d0cf1750be5eccec99706bc8aff3dc4fb852cb1 100755 (executable)
@@ -186,6 +186,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;
index 4c25801f1d166161e777ca96134271f35caf559b..83bf4c4daba1f1b702b355c1015372bc429fda19 100644 (file)
@@ -396,16 +396,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 */
index 13d125f2e54645b84f3d736c58a0f08defd73cd7..8717ce00cea55187c1dc913ec824768bca05b825 100755 (executable)
@@ -285,6 +285,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
index 996a5674a16b223b6ccf9f78ca7be6226716b83c..33231445c2761f6eb9910640698c5cd53e4e6436 100644 (file)
@@ -487,6 +487,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);