php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch return-previous-handler for PCNTL related Bug #72409Patch version 2016-06-18 08:11 UTC Return to Bug #72409 | Download this patchThis patch is obsolete Obsoleted by patches:
Developer: dave@mudsite.comLine 1 (now 1), was 18 lines, now 16 lines From 650a4f3709844111bc9f61453697b0896b712bdd Mon Sep 17 00:00:00 2001 From e4dc537e61f4ca792de0cdd9fe0ec08a127ce9a5 Mon Sep 17 00:00:00 2001 From: David Walker <dave@mudsite.com> Date: Sat, 18 Jun 2016 01:13:25 -0600 Date: Sat, 18 Jun 2016 02:08:53 -0600 Subject: [PATCH] Have pcntl_signal() return previously set handlers --- ext/pcntl/pcntl.c | 17 ++++++++++++++--- ext/pcntl/pcntl.c | 15 ++++++++------- ext/pcntl/tests/pcntl_signal.phpt | 7 ++++++- test.php | 13 +++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 test.php 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 5592b31..e50913d 100644 index 0b49d3c..e50913d 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -959,7 +959,7 @@ PHP_FUNCTION(pcntl_exec) Assigns a system signal handler to a PHP function */ Line 22 (now 20), was 36 lines, now 34 lines + zval *handle, *prev; zend_string *func_name; zend_long signo; zend_bool restart_syscalls = 1; @@ -1009,9 +1009,17 @@ PHP_FUNCTION(pcntl_signal) @@ -1009,8 +1009,12 @@ PHP_FUNCTION(pcntl_signal) } zend_string_release(func_name); - zval *prev = NULL; - prev = zend_hash_index_find(&PCNTL_G(php_signal_table), signo); + /* If we had a previous handler, save and return it */ + if ((prev = zend_hash_index_find(&PCNTL_G(php_signal_table), signo)) != NULL) { + ZVAL_DEREF(prev); + ZVAL_COPY(return_value, prev); + } + /* Add the function name to our signal table */ if (zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle)) { - if (Z_REFCOUNTED_P(handle)) Z_ADDREF_P(handle); + if (Z_REFCOUNTED_P(handle)) { + Z_ADDREF_P(handle); + } } if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == (Sigfunc *)SIG_ERR) { @@ -1019,7 +1027,10 @@ PHP_FUNCTION(pcntl_signal) php_error_docref(NULL, E_WARNING, "Error assigning signal"); if (Z_REFCOUNTED_P(handle)) { @@ -1024,12 +1028,9 @@ PHP_FUNCTION(pcntl_signal) RETURN_FALSE; } - RETURN_TRUE; + - if (!zend_is_callable(prev, 0, &func_name)) { - zend_string_release(func_name); + if (Z_ISNULL_P(return_value)) { + RETURN_TRUE; + } RETURN_TRUE; } - zend_string_release(func_name); - ZVAL_COPY(return_value, prev); } /* }}} */ diff --git a/ext/pcntl/tests/pcntl_signal.phpt b/ext/pcntl/tests/pcntl_signal.phpt Line 85 (now 81), was 26 lines, now 7 lines +string(4) "test" Warning: pcntl_signal() expects at least 2 parameters, 0 given in %s NULL diff --git a/test.php b/test.php new file mode 100644 index 0000000..ee71390 --- /dev/null +++ b/test.php @@ -0,0 +1,13 @@ +<?php +function foo() { +} +function bar() { +} + +pcntl_signal(SIGUSR1, 'foo'); +$func = pcntl_signal(SIGUSR1, 'bar'); +var_dump($func); + +pcntl_signal(SIGUSR1, function($signo) {}); +$func = pcntl_signal(SIGUSR1, 'bar'); +var_dump($func); -- 2.8.1.217.ge6ac6e1 |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Wed Apr 24 13:01:29 2024 UTC |