summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2007-02-13 19:53:42 +0000
committerNuno Lopes <nlopess@php.net>2007-02-13 19:53:42 +0000
commit9cc85b60307ac97c41620a68e218015aeb4bab2b (patch)
treefaa542ac3e1fe40779da0841956f80f6244dadd4
parentc8a4b1363861f4ec407a072f0789d515c2220474 (diff)
downloadphp-git-9cc85b60307ac97c41620a68e218015aeb4bab2b.tar.gz
Fixed bug #34794 (proc_close() hangs when used with two processes)
-rw-r--r--NEWS2
-rw-r--r--ext/standard/proc_open.c4
-rw-r--r--ext/standard/tests/general_functions/bug34794.phpt34
3 files changed, 40 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index aeb5c44645..279fd84b5a 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,8 @@ PHP NEWS
- Fixed bug #40109 (iptcembed fails on non-jfif jpegs). (Tony)
- Fixed bug #39836 (SplObjectStorage empty after unserialize). (Marcus)
- 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)
08 Feb 2007, PHP 5.2.1
- Added read-timeout context option "timeout" for HTTP streams. (Hannes, Ilia).
diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c
index 49755ef868..c285be6484 100644
--- a/ext/standard/proc_open.c
+++ b/ext/standard/proc_open.c
@@ -943,6 +943,10 @@ PHP_FUNCTION(proc_open)
descriptors[i].mode_flags), mode_string, NULL);
#else
stream = php_stream_fopen_from_fd(descriptors[i].parentend, mode_string, NULL);
+# if defined(F_SETFD) && defined(FD_CLOEXEC)
+ /* mark the descriptor close-on-exec, so that it won't be inherited by potential other children */
+ fcntl(descriptors[i].parentend, F_SETFD, FD_CLOEXEC);
+# endif
#endif
if (stream) {
zval *retfp;
diff --git a/ext/standard/tests/general_functions/bug34794.phpt b/ext/standard/tests/general_functions/bug34794.phpt
new file mode 100644
index 0000000000..3aacf7e518
--- /dev/null
+++ b/ext/standard/tests/general_functions/bug34794.phpt
@@ -0,0 +1,34 @@
+--TEST--
+bug #34794: proc_close() hangs when used with two processes
+--SKIPIF--
+<?php
+if (!is_executable('/bin/cat')) echo 'skip cat not found';
+?>
+--FILE--
+<?php
+echo "Opening process 1\n";
+$process1 = proc_open('/bin/cat', array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes1);
+
+echo "Opening process 2\n";
+$process2 = proc_open('/bin/cat', array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes2);
+
+
+echo "Closing process 1\n";
+fclose($pipes1[0]);
+fclose($pipes1[1]);
+proc_close($process1);
+
+echo "Closing process 2\n";
+fclose($pipes2[0]);
+fclose($pipes2[1]);
+proc_close($process2);
+
+echo "Done\n";
+
+?>
+--EXPECTF--
+Opening process 1
+Opening process 2
+Closing process 1
+Closing process 2
+Done