com php-src: Fix #72409 - return previous handler: ext/pcntl/pcntl.c ext/pcntl/php_pcntl.h ext/pcntl/tests/pcntl_signal_ge t_handler.phpt

From: Date: Wed, 06 Jul 2016 18:57:37 +0000
Subject: com php-src: Fix #72409 - return previous handler: ext/pcntl/pcntl.c ext/pcntl/php_pcntl.h ext/pcntl/tests/pcntl_signal_ge t_handler.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92839@lists.php.net to get a copy of this message
Commit: 217dcbcd911ad0552a4435fe979c069a5ddaef9f Author: David Walker <dave@mudsite.com> Sat, 2 Jul 2016 10:44:17 -0600 Committer: Aaron Piotrowski <aaron@trowski.com> Wed, 6 Jul 2016 13:57:37 -0500 Parents: 023b81259325c00012c0f703976c082be72dc5b9 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=217dcbcd911ad0552a4435fe979c069a5ddaef9f Log: 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. Bugs: https://bugs.php.net/72409 https://bugs.php..net/1952 https://bugs.php.net/1978 Changed paths: M ext/pcntl/pcntl.c M ext/pcntl/php_pcntl.h A ext/pcntl/tests/pcntl_signal_get_handler.phpt Diff: diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 5a7747a..811f740 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 816bffb..856ebe3 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 0000000..7d66f65 --- /dev/null +++ b/ext/pcntl/tests/pcntl_signal_get_handler.phpt @@ -0,0 +1,32 @@ +--TEST-- +pcntl_signal() +--SKIPIF-- +<?php if (!extension_loaded("pcntl")) print "skip"; ?> +<?php if (!extension_loaded("posix")) die("skip posix extension not available"); ?> +--FILE-- +<?php +var_dump(pcntl_signal_get_handler(SIGUSR1)); + +function pcntl_test($signo) {} +pcntl_signal(SIGUSR1, 'pcntl_test'); +var_dump(pcntl_signal_get_handler(SIGUSR1)); + +pcntl_signal(SIGUSR1, SIG_IGN); +var_dump(pcntl_signal_get_handler(SIGUSR1)); + +pcntl_signal(SIGUSR1, SIG_DFL); +var_dump(pcntl_signal_get_handler(SIGUSR1)); + +posix_kill(posix_getpid(), SIGUSR1); +pcntl_signal_dispatch(); + +echo "ok\n"; +?> +--EXPECTF-- +int(0) +string(10) "pcntl_test" +int(1) +int(0) +User defined signal 1 + +Termsig=10

« previous php.cvs (#92839) next »