From:             
Operating system: *nix
PHP version:      5.3.9
Package:          PCNTL related
Bug Type:         Feature/Change Request
Bug description:xp_socket.c functions should respect pcntl signal handlers

Description:
------------
Socket functions in xp_socket.c read and write indefinitely in case they
received  
any 
signal (read/write returned EINTR). Example, from 
php_sock_stream_wait_for_data():

while(1) {
retval = php_pollfd_for(sock->socket, PHP_POLLREADABLE, ptimeout);
if (retval == 0) sock->timeout_event = 1;
if (retval >= 0) break;
if (php_socket_errno() != EINTR) break;
}

The problem here is that this behavior is not compatible with pcntl signal

handling 
because pcntl signals are implemented using ticks and this code actually
does not 
exit 
even if we need to call signal handler.

Suggested fix for read() is to take into account existence of PCNTL and do
the 
following check:

if (php_socket_errno() != EINTR) break;
#ifdef PCNTL_G
else if(PCNTL_G(head)) break;
#endif

/* PCNTL_G(head) is pointer to a queue of signals
   that were caught and will be processed after next tick.
   This queue is empty if we do not register handlers for received signal.
*/

This fix (and adding ZEND_EXTERN_MODULE_GLOBALS(pcntl) to pcntl.c) gives
the 
expected result below

Test script:
---------------
<?php
declare(ticks = 1);
function sighandler($sig) {
echo "Caught signal $sig, exiting correctly\n";
exit(1);
}

pcntl_signal(SIGINT, 'sighandler', false);
pcntl_signal(SIGHUP, 'sighandler', false);

mysql_connect(); // assumes 'mysqlnd' as MySQL driver
mysql_query('SELECT SLEEP(100)'); // ignores SIGINT and SIGHUP for 100 sec

Expected result:
----------------
$ php test.php
^C
Warning: mysql_query(): MySQL server has gone away in test.php on line 14

Warning: mysql_query(): Error reading result set's header in 
/Users/nasretdinov/test.php on line 14
Caught signal 2, exiting correctly

Actual result:
--------------
$ php
^C
# ...after 100 sec...
Caught signal 2, exiting correctly

-- 
Edit bug report at https://bugs.php.net/bug.php?id=60938&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=60938&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=60938&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=60938&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=60938&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60938&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=60938&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=60938&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=60938&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=60938&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=60938&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=60938&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=60938&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=60938&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=60938&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=60938&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60938&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=60938&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=60938&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=60938&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=60938&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=60938&r=mysqlcfg

Reply via email to