From: Nuno Lopes Date: Wed, 14 Feb 2007 19:13:31 +0000 (+0000) Subject: Fixed bug #39322 (proc_terminate() destroys process resource) X-Git-Tag: php-5.2.2RC1~402 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d446564786505b49fdefd913ada77f1b0d3ce06f;p=php Fixed bug #39322 (proc_terminate() destroys process resource) --- diff --git a/NEWS b/NEWS index 279fd84b5a..206ccd1119 100644 --- 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) diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index c285be6484..7f92554ed1 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -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 index 0000000000..cb34599950 --- /dev/null +++ b/ext/standard/tests/general_functions/bug39322.phpt @@ -0,0 +1,44 @@ +--TEST-- +bug #39322: proc_terminate() loosing process resource +--SKIPIF-- + +--FILE-- + 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 index 0000000000..b89c616fe6 --- /dev/null +++ b/ext/standard/tests/general_functions/proc_open02.phpt @@ -0,0 +1,70 @@ +--TEST-- +proc_open +--SKIPIF-- + +--FILE-- + +--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!