diff options
author | SVN Migration <svn@php.net> | 2002-05-20 10:21:02 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2002-05-20 10:21:02 +0000 |
commit | 6fbb52450b5f4d43030f3086ed30768d50eb987d (patch) | |
tree | b8653f2600a337fdd0201c6dba2b8b51a3b94592 /ext/pcntl | |
parent | b1bcf9d7947385e44b3faf445ff60a3b7d181089 (diff) | |
download | php-git-RELEASE_0_4.tar.gz |
This commit was manufactured by cvs2svn to create tag 'RELEASE_0_4'.RELEASE_0_4
Diffstat (limited to 'ext/pcntl')
-rw-r--r-- | ext/pcntl/CREDITS | 2 | ||||
-rw-r--r-- | ext/pcntl/EXPERIMENTAL | 5 | ||||
-rw-r--r-- | ext/pcntl/README | 16 | ||||
-rw-r--r-- | ext/pcntl/config.m4 | 18 | ||||
-rwxr-xr-x | ext/pcntl/pcntl.c | 652 | ||||
-rw-r--r-- | ext/pcntl/php_pcntl.h | 84 | ||||
-rw-r--r-- | ext/pcntl/php_signal.c | 46 | ||||
-rw-r--r-- | ext/pcntl/php_signal.h | 28 | ||||
-rwxr-xr-x | ext/pcntl/test-pcntl.php | 35 | ||||
-rw-r--r-- | ext/pcntl/tests/001.phpt | 81 |
10 files changed, 0 insertions, 967 deletions
diff --git a/ext/pcntl/CREDITS b/ext/pcntl/CREDITS deleted file mode 100644 index 1d629d7adf..0000000000 --- a/ext/pcntl/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -pcntl -Jason Greene diff --git a/ext/pcntl/EXPERIMENTAL b/ext/pcntl/EXPERIMENTAL deleted file mode 100644 index 6443e99646..0000000000 --- a/ext/pcntl/EXPERIMENTAL +++ /dev/null @@ -1,5 +0,0 @@ -this extension is experimental, -its functions may change their names -or move to extension all together -so do not rely to much on them -you have been warned! diff --git a/ext/pcntl/README b/ext/pcntl/README deleted file mode 100644 index cadd11121c..0000000000 --- a/ext/pcntl/README +++ /dev/null @@ -1,16 +0,0 @@ -Process Control Module for PHP (pcntl) - -This module will attempt to implement all features related to process spawning and -control (fork(), waitpid(), signal(), WIF's, etc). This is extremly experimental, -with hope to become stable on most UNIX's. I greatly apreciate any feedback, fixes, -and or suggestions on how to improve/better implement -this functionality. - -Thanks, - -Jason Greeme < jason@inetgurus.net / jason@php.net > - - - - - diff --git a/ext/pcntl/config.m4 b/ext/pcntl/config.m4 deleted file mode 100644 index f24f038cb9..0000000000 --- a/ext/pcntl/config.m4 +++ /dev/null @@ -1,18 +0,0 @@ -dnl -dnl $Id$ -dnl - -dnl Process Control (pcntl) extentsion --EXPERIMENTAL-- -dnl TODO - Add platform checks - -PHP_ARG_ENABLE(pcntl, whether to enable pcntl support, -[ --enable-pcntl Enable experimental pcntl support (CLI/CGI only)]) - -if test "$PHP_PCNTL" != "no"; then - - AC_CHECK_FUNCS(fork, [ AC_DEFINE(HAVE_FORK,1,[ ]) ], [ AC_MSG_ERROR(pcntl: fork() not supported by this platform) ]) - AC_CHECK_FUNCS(waitpid, [ AC_DEFINE(HAVE_WAITPID,1,[ ]) ], [ AC_MSG_ERROR(pcntl: fork() not supported by this platform) ]) - AC_CHECK_FUNCS(sigaction, [ AC_DEFINE(HAVE_SIGACTION,1,[ ]) ], [ AC_MSG_ERROR(pcntl: sigaction() not supported by this platform) ]) - - PHP_NEW_EXTENSION(pcntl, pcntl.c php_signal.c, $ext_shared, cli) -fi diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c deleted file mode 100755 index 8f48cbb578..0000000000 --- a/ext/pcntl/pcntl.c +++ /dev/null @@ -1,652 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jason Greene <jason@inetgurus.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#define PCNTL_DEBUG 0 - -#if PCNTL_DEBUG -#define DEBUG_OUT printf("DEBUG: ");printf -#else -#define DEBUG_OUT -#endif - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "php_pcntl.h" - -ZEND_DECLARE_MODULE_GLOBALS(pcntl) - -static int le_pcntl; -static int pcntl_zend_extension_active; - -function_entry pcntl_functions[] = { - PHP_FE(pcntl_fork, NULL) - PHP_FE(pcntl_waitpid, second_arg_force_ref) - PHP_FE(pcntl_signal, NULL) - PHP_FE(pcntl_wifexited, NULL) - PHP_FE(pcntl_wifstopped, NULL) - PHP_FE(pcntl_wifsignaled, NULL) - PHP_FE(pcntl_wexitstatus, NULL) - PHP_FE(pcntl_wtermsig, NULL) - PHP_FE(pcntl_wstopsig, NULL) - PHP_FE(pcntl_exec, NULL) - {NULL, NULL, NULL} -}; - -zend_module_entry pcntl_module_entry = { - STANDARD_MODULE_HEADER, - "pcntl", - pcntl_functions, - PHP_MINIT(pcntl), - PHP_MSHUTDOWN(pcntl), - NULL, - NULL, - PHP_MINFO(pcntl), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_PCNTL -ZEND_GET_MODULE(pcntl) -#define PCNTL_ZEND_EXT ZEND_DLEXPORT -#else -#define PCNTL_ZEND_EXT -#endif - -PCNTL_ZEND_EXT zend_extension pcntl_extension_entry = { - "pcntl", - "1.0", - "Jason Greene", - "http://www.php.net", - "2001", - pcntl_zend_extension_startup, - pcntl_zend_extension_shutdown, - pcntl_zend_extension_activate, - pcntl_zend_extension_deactivate, - NULL, - NULL, - pcntl_zend_extension_statement_handler, - NULL, - NULL, - NULL, - NULL, - NULL -}; - - -void php_register_signal_constants(INIT_FUNC_ARGS) -{ - - /* Wait Constants */ -#ifdef WNOHANG - REGISTER_LONG_CONSTANT("WNOHANG", (long) WNOHANG, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef WUNTRACED - REGISTER_LONG_CONSTANT("WUNTRACED", (long) WUNTRACED, CONST_CS | CONST_PERSISTENT); -#endif - - /* Signal Constants */ - REGISTER_LONG_CONSTANT("SIG_IGN", (long) SIG_IGN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIG_DFL", (long) SIG_DFL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIG_ERR", (long) SIG_ERR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGHUP", (long) SIGHUP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGINT", (long) SIGINT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGQUIT", (long) SIGQUIT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGILL", (long) SIGILL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGTRAP", (long) SIGTRAP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGABRT", (long) SIGABRT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGIOT", (long) SIGIOT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGBUS", (long) SIGBUS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGFPE", (long) SIGFPE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGKILL", (long) SIGKILL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGUSR1", (long) SIGUSR1, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGSEGV", (long) SIGSEGV, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGUSR2", (long) SIGUSR2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGPIPE", (long) SIGPIPE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGALRM", (long) SIGALRM, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGTERM", (long) SIGTERM, CONST_CS | CONST_PERSISTENT); -#ifdef SIGSTKFLT - REGISTER_LONG_CONSTANT("SIGSTKFLT",(long) SIGSTKFLT, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef SIGCLD - REGISTER_LONG_CONSTANT("SIGCLD", (long) SIGCLD, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef SIGCHLD - REGISTER_LONG_CONSTANT("SIGCHLD", (long) SIGCHLD, CONST_CS | CONST_PERSISTENT); -#endif - REGISTER_LONG_CONSTANT("SIGCONT", (long) SIGCONT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGSTOP", (long) SIGSTOP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGTSTP", (long) SIGTSTP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGTTIN", (long) SIGTTIN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGTTOU", (long) SIGTTOU, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGURG", (long) SIGURG , CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGXCPU", (long) SIGXCPU, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGXFSZ", (long) SIGXFSZ, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGVTALRM",(long) SIGVTALRM, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGPROF", (long) SIGPROF, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGWINCH", (long) SIGWINCH, CONST_CS | CONST_PERSISTENT); -#ifdef SIGPOLL - REGISTER_LONG_CONSTANT("SIGPOLL", (long) SIGPOLL, CONST_CS | CONST_PERSISTENT); -#endif - REGISTER_LONG_CONSTANT("SIGIO", (long) SIGIO, CONST_CS | CONST_PERSISTENT); -#ifdef SIGPWR - REGISTER_LONG_CONSTANT("SIGPWR", (long) SIGPWR, CONST_CS | CONST_PERSISTENT); -#endif - REGISTER_LONG_CONSTANT("SIGSYS", (long) SIGSYS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SIGBABY", (long) SIGSYS, CONST_CS | CONST_PERSISTENT); -} - -static void php_pcntl_init_globals(zend_pcntl_globals *pcntl_globals) -{ - zend_hash_init(&pcntl_globals->php_signal_table, 16, NULL, NULL, 1); - - /* Just in case ... */ - memset(&pcntl_globals->php_signal_queue,0,sizeof(pcntl_globals->php_signal_queue)); - - zend_llist_init(&pcntl_globals->php_signal_queue, sizeof (long), NULL, 1); - pcntl_globals->signal_queue_ready = 0; - pcntl_globals->processing_signal_queue = 0; -} - -static void php_pcntl_shutdown_globals(zend_pcntl_globals *pcntl_globals) -{ - zend_hash_destroy(&pcntl_globals->php_signal_table); - zend_llist_destroy(&pcntl_globals->php_signal_queue); -} - -PHP_MINIT_FUNCTION(pcntl) -{ - php_register_signal_constants(INIT_FUNC_ARGS_PASSTHRU); - ZEND_INIT_MODULE_GLOBALS(pcntl, php_pcntl_init_globals, php_pcntl_shutdown_globals); - if (zend_register_extension(&pcntl_extension_entry, 0)==FAILURE) - return FAILURE; - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(pcntl) -{ - zend_hash_destroy(&PCNTL_G(php_signal_table)); - zend_llist_destroy(&PCNTL_G(php_signal_queue)); - return SUCCESS; -} - - - - -PHP_MINFO_FUNCTION(pcntl) -{ - php_info_print_table_start(); - php_info_print_table_header(2, "pcntl support", "enabled"); - php_info_print_table_end(); -} - -/* {{{ proto int pcntl_fork(void) - Forks the currently running process following the same behavior as the UNIX fork() system call*/ -PHP_FUNCTION(pcntl_fork) -{ - pid_t id; - - id = fork(); - if (id == -1) { - php_error(E_ERROR, "Error %d in %s", errno, get_active_function_name(TSRMLS_C)); - } - - RETURN_LONG((long) id); -} -/* }}} */ - -/* {{{ proto int pcntl_waitpid(long pid, long status, long options) - Waits on or returns the status of a forked child as defined by the waitpid() system call */ -PHP_FUNCTION(pcntl_waitpid) -{ - long pid, options = 0; - zval *z_status = NULL; - int status; - pid_t child_id; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|l", &pid, &z_status, &options) == FAILURE) - return; - - convert_to_long_ex(&z_status); - - status = Z_LVAL_P(z_status); - - child_id = waitpid((pid_t) pid, &status, options); - - Z_LVAL_P(z_status) = status; - - RETURN_LONG((long) child_id); -} -/* }}} */ - -/* {{{ proto bool pcntl_wifexited(long status) - Returns true if the child status code represents a successful exit */ -PHP_FUNCTION(pcntl_wifexited) -{ -#ifdef WIFEXITED - zval **status; - int status_word; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) { - WRONG_PARAM_COUNT; - } - - status_word = (int) Z_LVAL_PP(status); - - if (WIFEXITED(status_word)) RETURN_TRUE; -#endif - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool pcntl_wifstopped(long status) - Returns true if the child status code represents a stopped process (WUNTRACED must have been used with waitpid) */ -PHP_FUNCTION(pcntl_wifstopped) -{ -#ifdef WIFSTOPPED - zval **status; - int status_word; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) { - WRONG_PARAM_COUNT; - } - - status_word = (int) Z_LVAL_PP(status); - - if (WIFSTOPPED(status_word)) RETURN_TRUE; -#endif - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool pcntl_wifsignaled(long status) - Returns true if the child status code represents a process that was terminated due to a signal */ -PHP_FUNCTION(pcntl_wifsignaled) -{ -#ifdef WIFSIGNALED - zval **status; - int status_word; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) { - WRONG_PARAM_COUNT; - } - - status_word = (int) Z_LVAL_PP(status); - - if (WIFSIGNALED(status_word)) RETURN_TRUE; -#endif - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto int pcntl_wexitstatus(long status) - Returns the status code of a child's exit */ -PHP_FUNCTION(pcntl_wexitstatus) -{ -#ifdef WEXITSTATUS - zval **status; - int status_word; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) { - WRONG_PARAM_COUNT; - } - - status_word = (int) Z_LVAL_PP(status); - - /* WEXITSTATUS only returns 8 bits so we *MUST* cast this to signed char - if you want to have valid negative exit codes */ - RETURN_LONG((signed char) WEXITSTATUS(status_word)); -#else - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto int pcntl_wtermsig(long status) - Returns the number of the signal that terminated the process who's status code is passed */ -PHP_FUNCTION(pcntl_wtermsig) -{ -#ifdef WTERMSIG - zval **status; - int status_word; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) { - WRONG_PARAM_COUNT; - } - - status_word = (int) Z_LVAL_PP(status); - - RETURN_LONG(WTERMSIG(status_word)); -#else - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto int pcntl_wstopsig(long status) - Returns the number of the signal that caused the process to stop who's status code is passed */ -PHP_FUNCTION(pcntl_wstopsig) -{ -#ifdef WSTOPSIG - zval **status; - int status_word; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) { - WRONG_PARAM_COUNT; - } - - status_word = (int) Z_LVAL_PP(status); - - RETURN_LONG(WSTOPSIG(status_word)); -#else - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto bool pcntl_exec(string path [, array args [, array envs]]) - Executes specified program in current process space as defined by exec(2) */ -PHP_FUNCTION(pcntl_exec) -{ - zval *args, *envs; - zval **element; - HashTable *args_hash, *envs_hash; - int argc = 0, argi = 0; - int envc = 0, envi = 0; - int return_val = 0; - char **argv = NULL, **envp = NULL; - char **current_arg, **pair; - int pair_length; - char *key; - int key_length; - char *path; - int path_len; - long key_num; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|aa", &path, &path_len, &args, &envs) == FAILURE) { - return; - } - - if (ZEND_NUM_ARGS() > 1) { - /* Build argumnent list */ - args_hash = HASH_OF(args); - argc = zend_hash_num_elements(args_hash); - - argv = alloca((argc+2) * sizeof(char *)); - *argv = path; - for ( zend_hash_internal_pointer_reset(args_hash), current_arg = argv+1; - (argi < argc && (zend_hash_get_current_data(args_hash, (void **) &element) == SUCCESS)); - (argi++, current_arg++, zend_hash_move_forward(args_hash)) ) { - - convert_to_string_ex(element); - *current_arg = Z_STRVAL_PP(element); - } - *(current_arg) = NULL; - } else { - argv = alloca(2 * sizeof(char *)); - *argv = path; - *(argv+1) = NULL; - } - - if ( ZEND_NUM_ARGS() == 3 ) { - /* Build environment pair list */ - envs_hash = HASH_OF(envs); - envc = zend_hash_num_elements(envs_hash); - - envp = alloca((envc+1) * sizeof(char *)); - for ( zend_hash_internal_pointer_reset(envs_hash), pair = envp; - (envi < envc && (zend_hash_get_current_data(envs_hash, (void **) &element) == SUCCESS)); - (envi++, pair++, zend_hash_move_forward(envs_hash)) ) { - switch (return_val = zend_hash_get_current_key_ex(envs_hash, &key, &key_length, &key_num, 0, NULL)) { - case HASH_KEY_IS_LONG: - key = alloca(101); - snprintf(key, 100, "%ld", key_num); - key_length = strlen(key); - break; - case HASH_KEY_NON_EXISTANT: - pair--; - continue; - } - - convert_to_string_ex(element); - - /* Length of element + equal sign + length of key + null */ - pair_length = Z_STRLEN_PP(element) + key_length + 2; - *pair = emalloc(pair_length); - strlcpy(*pair, key, key_length); - strlcat(*pair, "=", pair_length); - strlcat(*pair, Z_STRVAL_PP(element), pair_length); - - /* Cleanup */ - if (return_val == HASH_KEY_IS_LONG) free_alloca(key); - } - *(pair) = NULL; - } - - if (execve(path, argv, envp) == -1) { - php_error(E_WARNING, "Error has occured in %s: (errno %d) %s", - get_active_function_name(TSRMLS_C), errno, strerror(errno)); - } - - /* Cleanup */ - if (envp != NULL) { - for (pair = envp; *pair != NULL; pair++) efree(*pair); - free_alloca(envp); - } - - free_alloca(argv); - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool pcntl_signal(long signo, mixed handle) - Assigns a system signal handler to a PHP function */ -PHP_FUNCTION(pcntl_signal) -{ - zval **signo, **handle; - char *func_name; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &signo, &handle) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(signo); - - /* Special long value case for SIG_DFL and SIG_IGN */ - if (Z_TYPE_PP(handle)==IS_LONG) { - if (Z_LVAL_PP(handle)!= (long) SIG_DFL && Z_LVAL_PP(handle) != (long) SIG_IGN) { - php_error(E_WARNING, "Invalid value for handle argument specifEied in %s", get_active_function_name(TSRMLS_C)); - } - if (php_signal(Z_LVAL_PP(signo), (Sigfunc *) Z_LVAL_PP(handle))==SIG_ERR) { - php_error(E_WARNING, "Error assigning singal in %s", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - RETURN_TRUE; - } - - if (Z_TYPE_PP(handle) != IS_STRING) { - php_error(E_WARNING, "Invalid type specified for handle argument in %s", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - - convert_to_string_ex(handle); /* Just in case */ - if (!zend_is_callable(*handle, 0, &func_name)) { - php_error(E_WARNING, "%s: %s is not a callable function name error", get_active_function_name(TSRMLS_C), func_name); - efree(func_name); - RETURN_FALSE; - } - efree(func_name); - - /* Add the function name to our signal table */ - zend_hash_index_update(&PCNTL_G(php_signal_table), Z_LVAL_PP(signo), Z_STRVAL_PP(handle), (Z_STRLEN_PP(handle) + 1) * sizeof(char), NULL); - - if (php_signal(Z_LVAL_PP(signo), pcntl_signal_handler)==SIG_ERR) { - php_error(E_WARNING, "Error assigning singal in %s", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* Note Old */ -static void old_pcntl_signal_handler(int signo) -{ - char *func_name; - zval *param, *call_name, *retval; - TSRMLS_FETCH(); - - DEBUG_OUT("Caught signal: %d\n", signo); - if (zend_hash_index_find(&PCNTL_G(php_signal_table), (long) signo, (void *) &func_name)==FAILURE) { - DEBUG_OUT("Signl handler not fount"); - return; - } - /* DEBUG_OUT("Signal handler found, Calling %s\n", func_name); */ - MAKE_STD_ZVAL(param); - MAKE_STD_ZVAL(call_name); - MAKE_STD_ZVAL(retval); - ZVAL_LONG(param, signo); - ZVAL_STRING(call_name, func_name, 1); - - /* Call php singal handler - Note that we do not report errors, and we ignore the return value */ - call_user_function(EG(function_table), NULL, call_name, retval, 1, ¶m TSRMLS_CC); - - zval_dtor(call_name); - efree(call_name); - efree(param); - efree(retval); - - return; -} - -/* Our custom signal handler that calls the appropriate php_function */ -static void pcntl_signal_handler(int signo) -{ - long signal_num = signo; - TSRMLS_FETCH(); - - DEBUG_OUT("Caught signo %d\n", signo); - if (! PCNTL_G(processing_signal_queue) && pcntl_zend_extension_active ) { - zend_llist_add_element(&PCNTL_G(php_signal_queue), &signal_num); - PCNTL_G(signal_queue_ready) = 1; - DEBUG_OUT("Added queue entry\n"); - } - return; -} - -/* Pcntl Zend Extension Hooks */ - -int pcntl_zend_extension_startup(zend_extension *extension) -{ - TSRMLS_FETCH(); - - DEBUG_OUT("Statup Called\n"); - pcntl_zend_extension_active = 1; - CG(extended_info) = 1; - return SUCCESS; -} - -void pcntl_zend_extension_shutdown(zend_extension *extension) -{ - DEBUG_OUT("Shutdown Called\n"); - return; -} - -void pcntl_zend_extension_activate(void) -{ - TSRMLS_FETCH(); - - DEBUG_OUT("Activate Called\n"); - pcntl_zend_extension_active = 1; - CG(extended_info) = 1; - return; -} - -void pcntl_zend_extension_deactivate(void) -{ - DEBUG_OUT("Deactivate Called\n"); - pcntl_zend_extension_active = 0; - return; -} - -/* Custom hook to ensure signals only get called at a safe poing in Zend's execute process */ -void pcntl_zend_extension_statement_handler(zend_op_array *op_array) -{ - zend_llist_element *element; - zval *param, *call_name, *retval; - char *func_name; - TSRMLS_FETCH(); - - /* Bail if the queue is empty or if we are already playing the queue*/ - if (! PCNTL_G(signal_queue_ready) || PCNTL_G(processing_signal_queue)) - return; - - /* Mark our queue empty */ - PCNTL_G(signal_queue_ready) = 0; - - /* If for some reason our signal queue is empty then return */ - if (zend_llist_count(&PCNTL_G(php_signal_queue)) <= 0) { - return; - } - - /* Disable queue so this function is not infinate */ - PCNTL_G(processing_signal_queue) = 1; - - /* Allocate */ - MAKE_STD_ZVAL(param); - MAKE_STD_ZVAL(call_name); - MAKE_STD_ZVAL(retval); - - /* Traverse through our signal queue and call the appropriate php functions */ - for (element = (&PCNTL_G(php_signal_queue))->head; element; element = element->next) { - long *signal_num = (long *)&element->data; - if (zend_hash_index_find(&PCNTL_G(php_signal_table), *signal_num, (void *) &func_name)==FAILURE) { - continue; - } - - ZVAL_LONG(param, *signal_num); - ZVAL_STRING(call_name, func_name, 0); - - /* Call php singal handler - Note that we do not report errors, and we ignore the return value */ - call_user_function(EG(function_table), NULL, call_name, retval, 1, ¶m TSRMLS_CC); - } - /* Clear */ - zend_llist_clean(&PCNTL_G(php_signal_queue)); - - /* Re-enable queue */ - PCNTL_G(processing_signal_queue) = 0; - - /* Clean up */ - efree(param); - efree(call_name); - efree(retval); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * indent-tabs-mode: t - * End: - */ diff --git a/ext/pcntl/php_pcntl.h b/ext/pcntl/php_pcntl.h deleted file mode 100644 index c555cb5441..0000000000 --- a/ext/pcntl/php_pcntl.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jason Greene <jason@inetgurus.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_PCNTL_H -#define PHP_PCNTL_H - -#include <sys/wait.h> -#include "php_signal.h" -#include "zend_extensions.h" -extern zend_module_entry pcntl_module_entry; -#define phpext_pcntl_ptr &pcntl_module_entry - -#ifdef PHP_WIN32 -#define PHP_PCNTL_API __declspec(dllexport) -#else -#define PHP_PCNTL_API -#endif - -PHP_MINIT_FUNCTION(pcntl); -PHP_MSHUTDOWN_FUNCTION(pcntl); -PHP_RINIT_FUNCTION(pcntl); -PHP_RSHUTDOWN_FUNCTION(pcntl); -PHP_MINFO_FUNCTION(pcntl); - -PHP_FUNCTION(pcntl_fork); -PHP_FUNCTION(pcntl_waitpid); -PHP_FUNCTION(pcntl_wifexited); -PHP_FUNCTION(pcntl_wifstopped); -PHP_FUNCTION(pcntl_wifsignaled); -PHP_FUNCTION(pcntl_wexitstatus); -PHP_FUNCTION(pcntl_wtermsig); -PHP_FUNCTION(pcntl_wstopsig); -PHP_FUNCTION(pcntl_signal); -PHP_FUNCTION(pcntl_exec); - -static void pcntl_signal_handler(int); - -/* Zend extension prototypes */ -int pcntl_zend_extension_startup(zend_extension *extension); -void pcntl_zend_extension_shutdown(zend_extension *extension); -void pcntl_zend_extension_activate(void); -void pcntl_zend_extension_deactivate(void); -void pcntl_zend_extension_statement_handler(zend_op_array *op_array); - - -ZEND_BEGIN_MODULE_GLOBALS(pcntl) - HashTable php_signal_table; - zend_llist php_signal_queue; - int signal_queue_ready; - int processing_signal_queue; -ZEND_END_MODULE_GLOBALS(pcntl) -#ifdef ZTS -#define PCNTL_G(v) TSRMG(pcntl_globals_id, zend_pcntl_globals *, v) -#else -#define PCNTL_G(v) (pcntl_globals.v) -#endif - -#endif /* PHP_PCNTL_H */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * indent-tabs-mode: t - * End: - */ diff --git a/ext/pcntl/php_signal.c b/ext/pcntl/php_signal.c deleted file mode 100644 index 41172a988b..0000000000 --- a/ext/pcntl/php_signal.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jason Greene <jason@inetgurus.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php_signal.h" - -/* php_signal using sigaction is taken verbatim from Advanced Programing - * in the Unix Environment by W. Richard Stevens p 298. */ -Sigfunc *php_signal(int signo, Sigfunc *func) -{ - - struct sigaction act,oact; - act.sa_handler = func; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - if (signo == SIGALRM) { -#ifdef SA_INTERRUPT - act.sa_flags |= SA_INTERRUPT; /* SunOS */ -#endif - } else { -#ifdef SA_RESTART - act.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */ -#endif - } - if (sigaction(signo, &act, &oact) < 0) - return SIG_ERR; - - return oact.sa_handler; -} - diff --git a/ext/pcntl/php_signal.h b/ext/pcntl/php_signal.h deleted file mode 100644 index 63baa4c3a3..0000000000 --- a/ext/pcntl/php_signal.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jason Greene <jason@inetgurus.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include <signal.h> -#ifndef PHP_SIGNAL_H -#define PHP_SIGNAL_H - -typedef void Sigfunc(int); -Sigfunc *php_signal(int signo, Sigfunc *func); - -#endif diff --git a/ext/pcntl/test-pcntl.php b/ext/pcntl/test-pcntl.php deleted file mode 100755 index 41334ba814..0000000000 --- a/ext/pcntl/test-pcntl.php +++ /dev/null @@ -1,35 +0,0 @@ -#!/opt/devel/php4/php -q -<? -function alarm_handle($signal){ - if ($signal==SIGALRM) print "Caught SIGALRM!!!\n"; -} -function usr1_handle($signal){ - if ($signal==SIGUSR1) print "Caught SIGUSR1!!!\n"; -} - -print "This test will demonstrate a fork followed by ipc via signals.\n"; - -$pid=pcntl_fork(); -if ($pid==0) { - pcntl_signal(SIGUSR1, "usr1_handle"); - pcntl_signal(SIGALRM, "alarm_handle"); - print "Child: Waiting for alarm.....\n"; - sleep(100); - print "Child: Waiting for usr1......\n"; - sleep(100); - print "Child: Resetting Alarm handler to Ignore....\n"; - pcntl_signal(SIGALRM, SIG_IGN); - sleep(10); - print "Done\n"; -} else { - print "Parent: Waiting 10 seconds....\n"; - sleep(10); - print "Parent: Sending SIGALRM to Child\n"; - posix_kill($pid,SIGALRM); - sleep(1); - print "Parent: Senging SIGUSR1 to Child\n"; - posix_kill($pid,SIGUSR1); - sleep(1); - print "Parent: Sending SIGALRM to Child\n"; - pcntl_waitpid($pid, &$status, $options); -} diff --git a/ext/pcntl/tests/001.phpt b/ext/pcntl/tests/001.phpt deleted file mode 100644 index 85ca4ab6e0..0000000000 --- a/ext/pcntl/tests/001.phpt +++ /dev/null @@ -1,81 +0,0 @@ ---TEST-- -Test pcntl wait functionality ---SKIPIF-- -<?php if (!extension_loaded("pcntl")) print "skip"; ?> ---POST-- ---GET-- ---FILE-- -<?php -function test_exit_waits(){ - print "\n\nTesting pcntl_wifexited and wexitstatus...."; - - $pid=pcntl_fork(); - if ($pid==0) { - sleep(1); - exit(-1); - } else { - $options=0; - pcntl_waitpid($pid, $status, $options); - if ( pcntl_wifexited($status) ) print "\nExited With: ". pcntl_wexitstatus($status); - } -} - -function test_exit_signal(){ - print "\n\nTesting pcntl_wifsignaled...."; - - $pid=pcntl_fork(); - - if ($pid==0) { - sleep(10); - exit; - } else { - $options=0; - posix_kill($pid, SIGTERM); - pcntl_waitpid($pid, $status, $options); - if ( pcntl_wifsignaled($status) ) { - $signal_print=pcntl_wtermsig($status); - if ($signal_print==SIGTERM) $signal_print="SIGTERM"; - print "\nProcess was terminated by signal : ". $signal_print; - } - - } -} - - -function test_stop_signal(){ - print "\n\nTesting pcntl_wifstopped and pcntl_wstopsig...."; - - $pid=pcntl_fork(); - - if ($pid==0) { - sleep(1); - exit; - } else { - $options=WUNTRACED; - posix_kill($pid, SIGSTOP); - pcntl_waitpid($pid, $status, $options); - if ( pcntl_wifstopped($status) ) { - $signal_print=pcntl_wstopsig($status); - if ($signal_print==SIGSTOP) $signal_print="SIGSTOP"; - print "\nProcess was stoped by signal : ". $signal_print; - } - posix_kill($pid, SIGCONT); - } -} - -print "Staring wait.h tests...."; -test_exit_waits(); -test_exit_signal(); -test_stop_signal(); -?> ---EXPECT-- -Staring wait.h tests.... - -Testing pcntl_wifexited and wexitstatus.... -Exited With: -1 - -Testing pcntl_wifsignaled.... -Process was terminated by signal : SIGTERM - -Testing pcntl_wifstopped and pcntl_wstopsig.... -Process was stoped by signal : SIGSTOP |