|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-11-19 03:41 UTC] kevin at nvwtv dot com dot tw
Description:
------------
Env:
FreeBSD 6.3-PRERELEASE
php5-5.2.5
pecl-expect-0.2.4
expect-5.43.0_3
In FreeBSD telnet to Win2003 code:
$stream=expect_popen("telnet -l $os_user $host_ip");
....
fclose($stream);
ps ax:
2348 p1- Z 0:00.04 <defunct>
13697 p2- Z 0:00.04 <defunct>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 07:00:02 2025 UTC |
The reason is that in unix you have to call wait() or waitpid() from libc to collect the return status of the child process. If not done so than the process will remain as zombie in the process table. Find below a patch introducing a expect_pclose() function to php-expect which closes the stream and calls waitpid(). If there is allready a expect_pclose() funciton or a RSHUTDOWN funcition doing this , why is it not included in the latests version 0.2.4 ??? --------------------------------------------------------------------------------- diff -bBd -u expect-0.2.4_a/config.m4 expect-0.2.4/config.m4 --- expect-0.2.4_a/config.m4 2007-09-09 17:43:36.000000000 +0200 +++ expect-0.2.4/config.m4 2008-06-12 16:16:20.000000000 +0200 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.4 2007/09/09 15:43:36 michael Exp $ +dnl $Id: config.m4,v 1.1 2008/06/12 14:16:20 hintermueller Exp $ dnl PHP_ARG_WITH(expect,for expect support, diff -bBd -u expect-0.2.4_a/expect.c expect-0.2.4/expect.c --- expect-0.2.4_a/expect.c 2007-10-20 09:13:09.000000000 +0200 +++ expect-0.2.4/expect.c 2008-07-17 19:13:52.000000000 +0200 @@ -21,11 +21,14 @@ #include "php_expect.h" #include <string.h> #include <errno.h> +#include <sys/types.h> +#include <sys/wait.h> /* {{{ expect_functions[] */ function_entry expect_functions[] = { PHP_FE(expect_popen, NULL) PHP_FE(expect_expectl, third_arg_force_ref) + PHP_FE(expect_pclose, NULL) { NULL, NULL, NULL } }; /* }}} */ @@ -153,6 +156,27 @@ /* {{{ + * proto resource expect_pclose (string command) + */ +PHP_FUNCTION(expect_pclose) +{ + + zval *z_stream; + php_stream *stream; + int command_len; + + if (ZEND_NUM_ARGS() != 1) { + WRONG_PARAM_COUNT; + } + if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_stream) == FAILURE) { + RETURN_FALSE; + } + php_stream_from_zval (stream, &z_stream); + php_stream_close(stream); + waitpid(-1,NULL,WUNTRACED); + RETURN_TRUE; +} +/* {{{ * proto resource expect_popen (string command) */ PHP_FUNCTION(expect_popen) diff -bBd -u expect-0.2.4_a/expect_fopen_wrapper.c expect-0.2.4/expect_fopen_wrapper.c --- expect-0.2.4_a/expect_fopen_wrapper.c 2007-10-19 20:52:39.000000000 +0200 +++ expect-0.2.4/expect_fopen_wrapper.c 2008-06-12 16:16:21.000000000 +0200 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: expect_fopen_wrapper.c,v 1.2 2007/09/09 15:43:36 michael Exp $ */ +/* $Id: expect_fopen_wrapper.c,v 1.1 2008/06/12 14:16:21 hintermueller Exp $ */ #include "php.h" #include "php_expect.h" diff -bBd -u expect-0.2.4_a/php_expect.h expect-0.2.4/php_expect.h --- expect-0.2.4_a/php_expect.h 2007-10-20 08:42:20.000000000 +0200 +++ expect-0.2.4/php_expect.h 2008-07-17 19:13:58.000000000 +0200 @@ -46,6 +46,7 @@ PHP_MINFO_FUNCTION(expect); PHP_FUNCTION(expect_popen); +PHP_FUNCTION(expect_pclose); PHP_FUNCTION(expect_expectl); extern php_stream_wrapper php_expect_wrapper; ------------------------------------------------------------------------ NOTE: this is only tested in linux/bsd/unix and alike. Do know nothing about windows. Where shall i send the patch to because copying form the web is not the best solution.There's a stream close handler that should do the job, and it's included into 0.2.4 release: static int php_expect_stream_close (php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC) { zval* z_pid = stream->wrapperdata; int s = 0; waitpid (Z_LVAL_P(z_pid), &s, 0); zval_ptr_dtor (&z_pid); stream->wrapperdata = NULL; return s; } This should work fine if you close the stream using fclose().The thing is that stream wrapper is only called for code such like: $stream=fopen("expect://telnet askjfddfdsf", "rw"); fclose($stream); but is never called for code like in original example: $stream=expect_popen("telnet -l $os_user $host_ip"); fclose($stream); so the bug still exists. php-pecl-expect-0.3.1