php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57918 leaving "zombies" after fclose (using expect_popen)
Submitted: 2007-11-19 03:41 UTC Modified: 2009-09-22 11:20 UTC
Votes:5
Avg. Score:4.0 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (20.0%)
From: kevin at nvwtv dot com dot tw Assigned:
Status: No Feedback Package: expect (PECL)
PHP Version: 5_2 CVS-2007-11-19 OS: FreeBSD 6.3-PRERELEASE
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kevin at nvwtv dot com dot tw
New email:
PHP Version: OS:

 

 [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>





Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-17 13:58 UTC] chistoph dot hintemrueller at psi dot ch
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.
 [2008-07-17 14:00 UTC] christoph dot hintermueller at psi dot ch
Sorry misspelled email address
 [2008-07-20 04:48 UTC] spektom at gmail dot com
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().
 [2009-09-22 11:20 UTC] spektom at gmail dot com
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2013-06-08 08:14 UTC] arekm at maven dot pl
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC