php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15125 pnctl_signal does not handle class's as callbacks - patch included
Submitted: 2002-01-20 10:57 UTC Modified: 2002-08-24 00:01 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: alan_k@php.net Assigned: jason (profile)
Status: Closed Package: *Extensibility Functions
PHP Version: 4.0CVS-2002-01-20 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alan_k@php.net
New email:
PHP Version: OS:

 

 [2002-01-20 10:57 UTC] alan_k@php.net
Have a go with this.- I'm assuming that zend_is_callable works like php_gtk_is_callable...

regards
alan

Index: pcntl.c
===================================================================
RCS file: /repository/php4/ext/pcntl/pcntl.c,v
retrieving revision 1.18
diff -u -r1.18 pcntl.c
--- pcntl.c     4 Jan 2002 14:08:25 -0000       1.18
+++ pcntl.c     20 Jan 2002 15:51:50 -0000
@@ -483,14 +483,8 @@
                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);
+               php_error(E_WARNING, "%s: argument 2 is not a callable function or method", get_active_function_name(TSRMLS_C));
                efree(func_name);
                RETURN_FALSE;
        }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-20 11:23 UTC] alan_k@php.net
Ok, forgot to modify your hash table... - this one doesnt segfault :)

Index: pcntl.c
===================================================================
RCS file: /repository/php4/ext/pcntl/pcntl.c,v
retrieving revision 1.18
diff -u -r1.18 pcntl.c
--- pcntl.c     4 Jan 2002 14:08:25 -0000       1.18
+++ pcntl.c     20 Jan 2002 16:20:50 -0000
@@ -483,21 +483,15 @@
                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);
+               php_error(E_WARNING, "%s: argument 2 is not a callable function or method", get_active_function_name(TSRMLS_C));
                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);
+       zend_hash_index_update(&PCNTL_G(php_signal_table), Z_LVAL_PP(signo), &handle, sizeof(zval *), 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));

 [2002-01-20 22:50 UTC] alan_k@php.net
this is a tested :) patch, eg. it appears to work, sample text-class-pcntl.php included at bottom

Index: pcntl.c
===================================================================
RCS file: /repository/php4/ext/pcntl/pcntl.c,v
retrieving revision 1.18
diff -u -r1.18 pcntl.c
--- pcntl.c	4 Jan 2002 14:08:25 -0000	1.18
+++ pcntl.c	21 Jan 2002 03:45:58 -0000
@@ -483,21 +483,15 @@
 		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);
+   	if (!zend_is_callable(*handle, 0, &func_name)) {
+		php_error(E_WARNING, "%s: Argument is not a callable function or method", 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);
+	zend_hash_index_update(&PCNTL_G(php_signal_table), Z_LVAL_PP(signo), &handle, sizeof(zval *), 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));

@@ -613,22 +606,22 @@
    
 	/* 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) {
+		if (zend_hash_index_find(&PCNTL_G(php_signal_table), *signal_num, (void *)  &call_name)==FAILURE) {
 			continue;
 		}
 		convert_to_long_ex(&param);
 		convert_to_string_ex(&call_name);
 		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, &param TSRMLS_CC);
 	}
 	/* Clear */
 	zend_llist_clean(&PCNTL_G(php_signal_queue));







------  test-class-pcntl.php


#!/opt/devel/php4/php -q
<?
dl("pcntl.so");


class test {
    
    
    function alarm_handle($signal){
             if ($signal==SIGALRM) print "Caught SIGALRM!!!\n";
    }
    function usr1_handle($signal){
             if ($signal==SIGUSR1) print "Caught SIGUSR1!!!\n";
    }
    
    function start() {
        //$options=NULL;
        //$status=NULL;
        print "This test will demonstrate a fork followed by ipc via signals.\n";
        
        $pid=pcntl_fork();
        if ($pid==0) {
           pcntl_signal(SIGUSR1, array(&$this,"usr1_handle"));
           pcntl_signal(SIGALRM, array(&$this,"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);
        }
    }
    
}

$test = new test();
$test->start();

 




 [2002-03-30 18:16 UTC] me at murpheous dot com
This is really irritating...
Tried the patch/fix provided, to no avail! :(
Tested in 4.1.2 and also latest 4.2 public RC (30/03/2002).
Simpler test scenario... Doesnt work.. no errors, no callbacks :(

Also tried setting class vars from outside class, e.g:
  pcntl_signal(SIGTERM, array(&$signal, "display_signal"));
after defining class.. no good either! :(

<?
class signalClass {

 function display_signal($signo) {
  echo "** $signo **\n";
  flush();
  exit();
 }

 function define_signals() {

  pcntl_signal(SIGTERM, array(&$this, "display_signal"));
  pcntl_signal(SIGHUP, array(&$this, "display_signal"));
  pcntl_signal(SIGINT, array(&$this, "display_signal"));
 }
}

$signal = new signalClass();
$signal->define_signals();

while(1) {
  // do something here..
  sleep(1);
}
?>

But this works as expected.. :(

<?

 function display_signal($signo) {
  echo "** $signo **\n";
  flush();
  exit();
 }


  pcntl_signal(SIGTERM, "display_signal");
  pcntl_signal(SIGHUP, "display_signal");
  pcntl_signal(SIGINT, "display_signal");

  while(1) {
   // do something here..
   sleep(1);
  }
?>
 [2002-06-04 06:49 UTC] mfischer@php.net
Alan, can you send a diff -u to php-dev@ against latest CVS ?
 [2002-07-05 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2002-07-05 01:37 UTC] alan_k@php.net
I will look at this soon promise...
 [2002-08-06 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2002-08-13 00:55 UTC] alan_k@php.net
testing and working patch has been posted to php-dev

assigning to jason :)

 [2002-08-24 00:01 UTC] jason@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

Implemented and scheduled for 4.3.X.

-Jason
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC