From: David Walker Date: Sat, 2 Jul 2016 16:44:17 +0000 (-0600) Subject: Fix #72409 - return previous handler X-Git-Tag: php-7.1.0beta1~162 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=217dcbcd911ad0552a4435fe979c069a5ddaef9f;p=php Fix #72409 - return previous handler This patch addresses https://bugs.php.net/bug.php?id=72409 This patch is applied to master compared to PR#1952 which was patching 5.6.x branch of PHP This patch takes into account discussions on PR #1978 Addressing that rather than have pcntl_signal() return a value to create a new function that can be used to get the current value of the signal handler. --- diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 5a7747acf4..811f7406ce 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -72,6 +72,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_pcntl_signal, 0, 0, 2) ZEND_ARG_INFO(0, restart_syscalls) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_pcntl_signal_get_handler, 0, 0, 1) + ZEND_ARG_INFO(0, signo) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_pcntl_sigprocmask, 0, 0, 2) ZEND_ARG_INFO(0, how) ZEND_ARG_INFO(0, set) @@ -159,6 +163,7 @@ const zend_function_entry pcntl_functions[] = { PHP_FE(pcntl_waitpid, arginfo_pcntl_waitpid) PHP_FE(pcntl_wait, arginfo_pcntl_wait) PHP_FE(pcntl_signal, arginfo_pcntl_signal) + PHP_FE(pcntl_signal_get_handler, arginfo_pcntl_signal_get_handler) PHP_FE(pcntl_signal_dispatch, arginfo_pcntl_void) PHP_FE(pcntl_wifexited, arginfo_pcntl_wifexited) PHP_FE(pcntl_wifstopped, arginfo_pcntl_wifstopped) @@ -997,7 +1002,7 @@ PHP_FUNCTION(pcntl_signal) php_error_docref(NULL, E_WARNING, "Error assigning signal"); RETURN_FALSE; } - zend_hash_index_del(&PCNTL_G(php_signal_table), signo); + zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle); RETURN_TRUE; } @@ -1023,6 +1028,29 @@ PHP_FUNCTION(pcntl_signal) } /* }}} */ +/* {{{ proto bool pcntl_signal_get_handler(int signo) + Gets signal handler */ +PHP_FUNCTION(pcntl_signal_get_handler) +{ + zval *prev_handle; + zend_long signo; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &signo) == FAILURE) { + return; + } + + if (signo < 1 || signo > 32) { + php_error_docref(NULL, E_WARNING, "Invalid signal"); + RETURN_FALSE; + } + + if ((prev_handle = zend_hash_index_find(&PCNTL_G(php_signal_table), signo)) != NULL) { + RETURN_ZVAL(prev_handle, 1, 0); + } else { + RETURN_LONG((long)SIG_DFL); + } +} + /* {{{ proto bool pcntl_signal_dispatch() Dispatch signals to signal handlers */ PHP_FUNCTION(pcntl_signal_dispatch) diff --git a/ext/pcntl/php_pcntl.h b/ext/pcntl/php_pcntl.h index 816bffb480..856ebe33ef 100644 --- a/ext/pcntl/php_pcntl.h +++ b/ext/pcntl/php_pcntl.h @@ -51,6 +51,7 @@ PHP_FUNCTION(pcntl_wexitstatus); PHP_FUNCTION(pcntl_wtermsig); PHP_FUNCTION(pcntl_wstopsig); PHP_FUNCTION(pcntl_signal); +PHP_FUNCTION(pcntl_signal_get_handler); PHP_FUNCTION(pcntl_signal_dispatch); PHP_FUNCTION(pcntl_get_last_error); PHP_FUNCTION(pcntl_strerror); diff --git a/ext/pcntl/tests/pcntl_signal_get_handler.phpt b/ext/pcntl/tests/pcntl_signal_get_handler.phpt new file mode 100644 index 0000000000..7d66f65cdf --- /dev/null +++ b/ext/pcntl/tests/pcntl_signal_get_handler.phpt @@ -0,0 +1,32 @@ +--TEST-- +pcntl_signal() +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +int(0) +string(10) "pcntl_test" +int(1) +int(0) +User defined signal 1 + +Termsig=10