]> granicus.if.org Git - php/commitdiff
Fixed bug #39322 (proc_terminate() destroys process resource)
authorNuno Lopes <nlopess@php.net>
Wed, 14 Feb 2007 19:13:31 +0000 (19:13 +0000)
committerNuno Lopes <nlopess@php.net>
Wed, 14 Feb 2007 19:13:31 +0000 (19:13 +0000)
NEWS
ext/standard/proc_open.c
ext/standard/tests/general_functions/bug39322.phpt [new file with mode: 0644]
ext/standard/tests/general_functions/proc_open02.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 279fd84b5a4d7c070cfa1462c654f646810bfebf..206ccd1119ddd7bb9d46ecc559e8a77f84904dd9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ PHP                                                                        NEWS
 - Fixed bug #40410 (ext/posix does not compile on MacOS 10.3.9). (Tony)
 - Fixed bug #40109 (iptcembed fails on non-jfif jpegs). (Tony)
 - Fixed bug #39836 (SplObjectStorage empty after unserialize). (Marcus)
+- Fixed bug #39322 (proc_terminate() destroys process resource). (Nuno)
 - Fixed bug #37799 (ftp_ssl_connect() falls back to non-ssl connection). (Nuno)
 - Fixed bug #34794 (proc_close() hangs when used with two processes).
   (jdolecek at netbsd dot org, Nuno)
index c285be64848a0a5fb70aa579ef8057953fcfe35a..7f92554ed1ec168208fea2b733d9b2e55e90a07f 100644 (file)
@@ -300,7 +300,7 @@ PHP_MINIT_FUNCTION(proc_open)
 }
 /* }}} */
 
-/* {{{ proto int proc_terminate(resource process [, long signal])
+/* {{{ proto bool proc_terminate(resource process [, long signal])
    kill a process opened by proc_open */
 PHP_FUNCTION(proc_terminate)
 {
@@ -315,13 +315,18 @@ PHP_FUNCTION(proc_terminate)
        ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open);
        
 #ifdef PHP_WIN32
-       TerminateProcess(proc->childHandle, 255);
+       if (TerminateProcess(proc->childHandle, 255)) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
 #else
-       kill(proc->child, sig_no);
+       if (kill(proc->child, sig_no) == 0) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
 #endif
-       
-       zend_list_delete(Z_LVAL_P(zproc));
-       RETURN_LONG(FG(pclose_ret));
 }
 /* }}} */
 
diff --git a/ext/standard/tests/general_functions/bug39322.phpt b/ext/standard/tests/general_functions/bug39322.phpt
new file mode 100644 (file)
index 0000000..cb34599
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+bug #39322: proc_terminate() loosing process resource
+--SKIPIF--
+<?php
+if (!is_executable('/bin/sleep')) echo 'skip sleep not found';
+?>
+--FILE--
+<?php
+$descriptors = array(
+    0 => array('pipe', 'r'),
+    1 => array('pipe', 'w'),
+    2 => array('pipe', 'w'));
+
+$pipes = array();
+
+$process = proc_open('/bin/sleep 120', $descriptors, $pipes);
+
+proc_terminate($process);
+sleep(1); // wait a bit to let the process finish
+var_dump(proc_get_status($process));
+
+echo "Done!\n";
+
+?>
+--EXPECTF--
+array(8) {
+  ["command"]=>
+  string(14) "/bin/sleep 120"
+  ["pid"]=>
+  int(%d)
+  ["running"]=>
+  bool(false)
+  ["signaled"]=>
+  bool(true)
+  ["stopped"]=>
+  bool(false)
+  ["exitcode"]=>
+  int(-1)
+  ["termsig"]=>
+  int(15)
+  ["stopsig"]=>
+  int(0)
+}
+Done!
diff --git a/ext/standard/tests/general_functions/proc_open02.phpt b/ext/standard/tests/general_functions/proc_open02.phpt
new file mode 100644 (file)
index 0000000..b89c616
--- /dev/null
@@ -0,0 +1,70 @@
+--TEST--
+proc_open
+--SKIPIF--
+<?php
+if (!is_executable('/bin/sleep')) echo 'skip no sleep';
+if (!is_executable('/bin/nohup')) echo 'skip no nohup';
+?>
+--FILE--
+<?php
+$ds = array(array('pipe', 'r'));
+
+$cat = proc_open(
+       '/bin/nohup /bin/sleep 50',
+       $ds,
+       $pipes
+);
+
+var_dump(proc_terminate($cat, 1)); // send a SIGHUP
+sleep(1);
+var_dump(proc_get_status($cat));
+
+var_dump(proc_terminate($cat)); // now really quit it
+sleep(1);
+var_dump(proc_get_status($cat));
+
+proc_close($cat);
+
+echo "Done!\n";
+
+?>
+--EXPECTF--
+bool(true)
+array(8) {
+  ["command"]=>
+  string(24) "/bin/nohup /bin/sleep 50"
+  ["pid"]=>
+  int(%d)
+  ["running"]=>
+  bool(true)
+  ["signaled"]=>
+  bool(false)
+  ["stopped"]=>
+  bool(false)
+  ["exitcode"]=>
+  int(-1)
+  ["termsig"]=>
+  int(0)
+  ["stopsig"]=>
+  int(0)
+}
+bool(true)
+array(8) {
+  ["command"]=>
+  string(24) "/bin/nohup /bin/sleep 50"
+  ["pid"]=>
+  int(%d)
+  ["running"]=>
+  bool(false)
+  ["signaled"]=>
+  bool(true)
+  ["stopped"]=>
+  bool(false)
+  ["exitcode"]=>
+  int(-1)
+  ["termsig"]=>
+  int(15)
+  ["stopsig"]=>
+  int(0)
+}
+Done!