com php-src: Dereferencing process-handles no longer waits on those processes.: NEWS ext/standard/file.c ext/standard/file.h ext/standard/proc_open.c
| From: | Lars Strojny | Date: | Tue, 15 Jan 2013 20:50:35 +0000 |
| Subject: | com php-src: Dereferencing process-handles no longer waits on those processes.: NEWS ext/standard/file.c ext/standard/file.h ext/standard/proc_open.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-70991@lists.php.net to get a copy of this message | ||
Commit: dba22c08640b02e68bfea68440246fec1fb7459d
Author: Jille Timmermans <jille@quis.cx> Tue, 15 Jan 2013 11:25:55 +0100
Committer: Lars Strojny <lstrojny@php.net> Tue, 15 Jan 2013 21:50:35 +0100
Parents: 1bd193ed36d413f0d919856f65feb35a0b1580f3
Branches: PHP-5.5
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dba22c08640b02e68bfea68440246fec1fb7459d
Log:
Dereferencing process-handles no longer waits on those processes.
Implements FR #46487
Bugs:
https://bugs.php.net/46487
Changed paths:
M NEWS
M ext/standard/file.c
M ext/standard/file.h
M ext/standard/proc_open.c
Diff:
diff --git a/NEWS b/NEWS
index 4145dc5..212029c 100644
--- a/NEWS
+++ b/NEWS
@@ -247,4 +247,7 @@ PHP NEWS
. Fixed bug #63248 (Load multiple magic files from a directory under Windows).
(Anatoliy)
+- General improvements:
+ . Implemented FR #46487 (Dereferencing process-handles no longer waits on those processes).
(Jille Timmermans)
+
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 74577ac..cf8b159 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -159,6 +159,7 @@ static ZEND_RSRC_DTOR_FUNC(file_context_dtor)
static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC)
{
FG(pclose_ret) = 0;
+ FG(pclose_wait) = 0;
FG(user_stream_current_filename) = NULL;
FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE;
FG(wrapper_errors) = NULL;
@@ -960,7 +961,9 @@ PHP_FUNCTION(pclose)
PHP_STREAM_TO_ZVAL(stream, &arg1);
+ FG(pclose_wait) = 1;
zend_list_delete(stream->rsrc_id);
+ FG(pclose_wait) = 0;
RETURN_LONG(FG(pclose_ret));
}
/* }}} */
diff --git a/ext/standard/file.h b/ext/standard/file.h
index 0a4512e..2bcdfd6 100644
--- a/ext/standard/file.h
+++ b/ext/standard/file.h
@@ -115,7 +115,7 @@ typedef struct _php_meta_tags_data {
php_meta_tags_token php_next_meta_token(php_meta_tags_data * TSRMLS_DC);
typedef struct {
- int pclose_ret;
+ int pclose_ret;
size_t def_chunk_size;
long auto_detect_line_endings;
long default_socket_timeout;
@@ -126,6 +126,7 @@ typedef struct {
HashTable *stream_wrappers; /* per-request copy of url_stream_wrappers_hash */
HashTable *stream_filters; /* per-request copy of stream_filters_hash */
HashTable *wrapper_errors; /* key: wrapper address; value: linked list of char* */
+ int pclose_wait;
} php_file_globals;
#ifdef ZTS
diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c
index 1edfe78..4e39a40 100644
--- a/ext/standard/proc_open.c
+++ b/ext/standard/proc_open.c
@@ -208,6 +208,7 @@ static void proc_open_rsrc_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
DWORD wstatus;
#elif HAVE_SYS_WAIT_H
int wstatus;
+ int waitpid_options = 0;
pid_t wait_pid;
#endif
@@ -220,18 +221,27 @@ static void proc_open_rsrc_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
}
#ifdef PHP_WIN32
- WaitForSingleObject(proc->childHandle, INFINITE);
+ if (FG(pclose_wait)) {
+ WaitForSingleObject(proc->childHandle, INFINITE);
+ }
GetExitCodeProcess(proc->childHandle, &wstatus);
- FG(pclose_ret) = wstatus;
+ if (wstatus == STILL_ACTIVE) {
+ FG(pclose_ret) = -1;
+ } else {
+ FG(pclose_ret) = wstatus;
+ }
CloseHandle(proc->childHandle);
#elif HAVE_SYS_WAIT_H
+ if (!FG(pclose_wait)) {
+ waitpid_options = WNOHANG;
+ }
do {
- wait_pid = waitpid(proc->child, &wstatus, 0);
+ wait_pid = waitpid(proc->child, &wstatus, waitpid_options);
} while (wait_pid == -1 && errno == EINTR);
- if (wait_pid == -1) {
+ if (wait_pid <= 0) {
FG(pclose_ret) = -1;
} else {
if (WIFEXITED(wstatus))
@@ -300,7 +310,9 @@ PHP_FUNCTION(proc_close)
ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process",
le_proc_open);
+ FG(pclose_wait) = 1;
zend_list_delete(Z_LVAL_P(zproc));
+ FG(pclose_wait) = 0;
RETURN_LONG(FG(pclose_ret));
}
/* }}} */