Skip to content

Commit

Permalink
Fixed bug #18998 (Change expect.logfile on runtime leave file descrip…
Browse files Browse the repository at this point in the history
…tor opened)

git-svn-id: http://svn.php.net/repository/pecl/expect/trunk@304243 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Michael Spector committed Oct 10, 2010
1 parent 324cf31 commit 3df1f5d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
27 changes: 26 additions & 1 deletion expect.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions package.xml
Expand Up @@ -14,19 +14,19 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>michael@php.net</email>
<active>yes</active>
</lead>
<date>2009-11-05</date>
<time>12:48:54</time>
<date>2010-10-10</date>
<time>09:28:00</time>
<version>
<release>0.2.5</release>
<api>0.2.5</api>
<release>0.2.6</release>
<api>0.2.6</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Fixed bug #14768 (configure error in Ubuntu 8.04)
Fixed bug #18998 (Change expect.logfile on runtime leave file descriptor opened)
</notes>
<contents>
<dir name="/">
Expand Down
12 changes: 11 additions & 1 deletion php_expect.h
Expand Up @@ -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)
Expand All @@ -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 */
Expand Down

0 comments on commit 3df1f5d

Please sign in to comment.