From c92a2219efed2cd54633bc56d7fdc86c5175e05e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 5 Dec 2003 13:45:00 +0000 Subject: [PATCH] Add optional array argument to proc_open() to specify additional options for the child process. The first option is "suppress_errors" which will disable any dialog boxes that arise from missing DLL's and suppress the GPF dialog. Use this new feature in the test suite, so that crashing tests don't block the test run; useful for un-attended execution. --- ext/standard/proc_open.c | 30 ++++++++++++++++++++++++++---- run-tests.php | 3 ++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index daf4985050..d23bc4076c 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -444,16 +444,16 @@ struct php_proc_open_descriptor_item { }; /* }}} */ -/* {{{ proto resource proc_open(string command, array descriptorspec, array &pipes [, string cwd [, array env]]) +/* {{{ proto resource proc_open(string command, array descriptorspec, array &pipes [, string cwd [, array env] [, array other_options]]) Run a process with more control over it's file descriptors */ PHP_FUNCTION(proc_open) { - char *command, *cwd=NULL; long command_len, cwd_len; zval *descriptorspec; zval *pipes; zval *environment = NULL; + zval *other_options = NULL; php_process_env_t env; int ndesc = 0; int i; @@ -466,13 +466,16 @@ PHP_FUNCTION(proc_open) BOOL newprocok; SECURITY_ATTRIBUTES security; char *command_with_cmd; + UINT old_error_mode; + int suppress_errors = 0; #endif php_process_id_t child; struct php_process_handle *proc; int is_persistent = 0; /* TODO: ensure that persistent procs will work */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz|s!a!", &command, - &command_len, &descriptorspec, &pipes, &cwd, &cwd_len, &environment) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz|s!a!a!", &command, + &command_len, &descriptorspec, &pipes, &cwd, &cwd_len, &environment, + &other_options) == FAILURE) { RETURN_FALSE; } @@ -480,6 +483,15 @@ PHP_FUNCTION(proc_open) RETURN_FALSE; } + if (other_options) { + zval **item; + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(other_options), "suppress_errors", sizeof("suppress_errors"), (void**)&item)) { + if (Z_TYPE_PP(item) == IS_BOOL && Z_BVAL_PP(item)) { + suppress_errors = 1; + } + } + } + command_len = strlen(command); if (environment) { @@ -669,7 +681,17 @@ PHP_FUNCTION(proc_open) command_with_cmd = emalloc(command_len + sizeof(COMSPEC_9X) + 1 + sizeof(" /c ")); sprintf(command_with_cmd, "%s /c %s", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command); + + if (suppress_errors) { + old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX); + } + newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, NORMAL_PRIORITY_CLASS, env.envp, cwd, &si, &pi); + + if (suppress_errors) { + SetErrorMode(old_error_mode); + } + efree(command_with_cmd); if (FALSE == newprocok) { diff --git a/run-tests.php b/run-tests.php index b1493f5729..0b4f6afa13 100755 --- a/run-tests.php +++ b/run-tests.php @@ -117,6 +117,7 @@ if (getenv('TEST_PHP_EXECUTABLE')) { putenv("TEST_PHP_EXECUTABLE=$php"); } } + if (empty($php) || !file_exists($php)) { error("environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!"); } @@ -588,7 +589,7 @@ function system_with_timeout($commandline) 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') - ), $pipes); + ), $pipes, null, null, array("suppress_errors" => true)); if (!$proc) return false; -- 2.50.1