php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #72409
Patch return-previous-handler revision 2016-06-18 08:20 UTC by dave at mudsite dot com
revision 2016-06-18 08:14 UTC by dave at mudsite dot com
revision 2016-06-18 08:11 UTC by dave at mudsite dot com

Patch return-previous-handler for PCNTL related Bug #72409

Patch version 2016-06-18 08:20 UTC

Return to Bug #72409 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions: 2016-06-18 08:20 UTC | 2016-06-18 08:14 UTC | 2016-06-18 08:11 UTC

Developer: dave@mudsite.com


 From e4dc537e61f4ca792de0cdd9fe0ec08a127ce9a5 Mon Sep 17 00:00:00 2001
 From aaa123a375e17a08f2f441b932e6165899edeb64 Mon Sep 17 00:00:00 2001
  From: David Walker <dave@mudsite.com>
 Date: Sat, 18 Jun 2016 02:08:53 -0600
 Date: Sat, 18 Jun 2016 01:13:25 -0600
  Subject: [PATCH] Have pcntl_signal() return previously set handlers
  
  ---
  ext/pcntl/pcntl.c                 | 15 ++++++++-------
  ext/pcntl/pcntl.c                 | 17 ++++++++++++++---
   ext/pcntl/tests/pcntl_signal.phpt |  7 ++++++-
  2 files changed, 14 insertions(+), 8 deletions(-)
  2 files changed, 20 insertions(+), 4 deletions(-)
  
  diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
 index 0b49d3c..e50913d 100644
 index 5592b31..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 */


  +	zval *handle, *prev;
   	zend_string *func_name;
   	zend_long signo;
   	zend_bool restart_syscalls = 1;
 @@ -1009,8 +1009,12 @@ PHP_FUNCTION(pcntl_signal)
 @@ -1009,9 +1009,17 @@ 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)) {
 @@ -1024,12 +1028,9 @@ PHP_FUNCTION(pcntl_signal)
 -		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");
   		RETURN_FALSE;
   	}
  
 -	if (!zend_is_callable(prev, 0, &func_name)) {
 -		zend_string_release(func_name);
 -	RETURN_TRUE;
 +
  +	if (Z_ISNULL_P(return_value)) {
  		RETURN_TRUE;
  	}
 -    zend_string_release(func_name);
 -    ZVAL_COPY(return_value, prev);
 +		RETURN_TRUE;
 +	}
   }
   /* }}} */
   
  diff --git a/ext/pcntl/tests/pcntl_signal.phpt b/ext/pcntl/tests/pcntl_signal.phpt
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Aug 04 14:01:24 2021 UTC