From 3df1f5db6572fdc0157c58ea53c171b8325af736 Mon Sep 17 00:00:00 2001 From: Michael Spector Date: Sun, 10 Oct 2010 07:37:35 +0000 Subject: [PATCH] Fixed bug #18998 (Change expect.logfile on runtime leave file descriptor opened) git-svn-id: http://svn.php.net/repository/pecl/expect/trunk@304243 c90b9560-bf6c-de11-be94-00142212c4b1 --- expect.c | 27 ++++++++++++++++++++++++++- package.xml | 10 +++++----- php_expect.h | 12 +++++++++++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/expect.c b/expect.c index 3449dbf..6e6daf5 100644 --- a/expect.c +++ b/expect.c @@ -61,6 +61,26 @@ zend_module_entry expect_module_entry = { ZEND_GET_MODULE(expect) #endif +ZEND_DECLARE_MODULE_GLOBALS(expect) + +/* {{{ php_expect_init_globals + */ +static void php_expect_init_globals (zend_expect_globals *globals TSRMLS_DC) +{ + globals->logfile_stream = NULL; +} +/* }}} */ + +/* {{{ php_expect_destroy_globals + */ +static void php_expect_destroy_globals(zend_expect_globals *globals TSRMLS_DC) +{ + if (globals->logfile_stream) { + php_stream_close(globals->logfile_stream); + } +} +/* }}} */ + /* {{{ PHP_INI_MH * */ static PHP_INI_MH(OnSetExpectTimeout) @@ -91,8 +111,11 @@ static PHP_INI_MH(OnSetExpectLogUser) * */ static PHP_INI_MH(OnSetExpectLogFile) { + if (EXPECT_G(logfile_stream)) { + php_stream_close(EXPECT_G(logfile_stream)); + } if (new_value_length > 0) { - php_stream *stream = php_stream_open_wrapper (new_value, "a", 0, NULL); + php_stream* stream = php_stream_open_wrapper (new_value, "a", 0, NULL); if (!stream) { php_error_docref (NULL TSRMLS_CC, E_ERROR, "could not open log file for writing"); return FAILURE; @@ -101,8 +124,10 @@ static PHP_INI_MH(OnSetExpectLogFile) if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void **) &exp_logfile, REPORT_ERRORS) != SUCCESS) { return FAILURE; } + EXPECT_G(logfile_stream) = stream; exp_logfile_all = 1; } else { + EXPECT_G(logfile_stream) = NULL; exp_logfile = NULL; exp_logfile_all = 0; } diff --git a/package.xml b/package.xml index d5ba3f4..4e1edf3 100644 --- a/package.xml +++ b/package.xml @@ -14,11 +14,11 @@ http://pear.php.net/dtd/package-2.0.xsd"> michael@php.net yes - 2009-11-05 - + 2010-10-10 + - 0.2.5 - 0.2.5 + 0.2.6 + 0.2.6 beta @@ -26,7 +26,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> PHP License -Fixed bug #14768 (configure error in Ubuntu 8.04) +Fixed bug #18998 (Change expect.logfile on runtime leave file descriptor opened) diff --git a/php_expect.h b/php_expect.h index ed4f600..8874e66 100644 --- a/php_expect.h +++ b/php_expect.h @@ -35,7 +35,7 @@ extern zend_module_entry expect_module_entry; #define phpext_expect_ptr &expect_module_entry -#define PHP_EXPECT_VERSION "0.2.5-dev" +#define PHP_EXPECT_VERSION "0.2.6-dev" #ifdef PHP_WIN32 #define PHP_EXPECT_API __declspec(dllexport) @@ -52,6 +52,16 @@ PHP_FUNCTION(expect_expectl); extern php_stream_wrapper php_expect_wrapper; +ZEND_BEGIN_MODULE_GLOBALS(expect) + php_stream* logfile_stream; +ZEND_END_MODULE_GLOBALS(expect) + +#ifdef ZTS +#define EXPECT_G(v) TSRMG(expect_globals_id, zend_expect_globals *, v) +#else +#define EXPECT_G(v) (expect_globals.v) +#endif + #ifdef ZTS #include "TSRM.h" #endif /* ZTS */