From:             axelluttgens at swing dot be
Operating system: Mac OS 10.4.7
PHP version:      4.4.2
PHP Bug Type:     PCNTL related
Bug description:  Incorrect return address after the execution of a signal 
handler?

Description:
------------
It seems there is a problem with the construction of the return address to
be used after an interrupt handler.

Now, I'm not sure whether the problem is a general one, or more precisely
located in the socket_xxx() family of functions.
I used the socket_select() function for building the example, as I needed
a function whose execution is liable to be suspended until the occurence
of an interrupt.

But the "workaround" described hereafter anyway seems to reveal some
misbehavior.

Reproduce code:
---------------
Create an executable file, say "sigtest.php", with following contents:

#!/usr/local/bin/php

<?php

declare(ticks = 1);

$gotINT = FALSE;

function SaveINT()
{
        $GLOBALS['gotINT'] = TRUE;
        echo "Received SIGINT\n";
}

function HandleINT()
{
        echo "Handling SIGINT\n";
}

function PollSigs()
{
        if ($GLOBALS['gotINT'])
                HandleINT();
}

pcntl_signal(SIGINT, 'SaveINT');

$endpoint = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($endpoint, '127.0.0.1', 12345);
socket_listen($endpoint, 10);
while (!socket_select($r = array($endpoint), $w = NULL, $e = NULL, NULL))
        if (($err = socket_last_error()) === SOCKET_EINTR)
        {
                # $err = $err;
                PollSigs();
        }
        else
        {
                echo "socket_select() failed with $err\n";
                exit(1);
        }

?>

Expected result:
----------------
During execution of above file on the terminal, a break (^C) should result
in:

1. the capture of SIGINT, and thus the execution of SaveINT(),
2. the continuation of execution after socket_select(), and thus the
execution of HandleINT() consecutively to the call of PollSigs(). 

Actual result:
--------------
[1] With above code, launching the executable yields:

$ /Volumes/Data/Sources/sigtest.php 

^C
Warning: socket_select() unable to select [4]: Interrupted system call in
/Volumes/Data/Sources/sigtest.php on line 31
Received SIGINT
^C
Warning: socket_select() unable to select [4]: Interrupted system call in
/Volumes/Data/Sources/sigtest.php on line 31
Handling SIGINT
Received SIGINT

[2] Now, uncomment the
   # $err = $err;
line in the source and launch the executable again:

$ /Volumes/Data/Sources/sigtest.php 

^C
Warning: socket_select() unable to select [4]: Interrupted system call in
/Volumes/Data/Sources/sigtest.php on line 31
Received SIGINT
Handling SIGINT
^C
Warning: socket_select() unable to select [4]: Interrupted system call in
/Volumes/Data/Sources/sigtest.php on line 31
Received SIGINT
Handling SIGINT

The dummy instruction (ie, $err = $err;) thus allows to restore exepected
behavior.

-- 
Edit bug report at http://bugs.php.net/?id=38273&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38273&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38273&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38273&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38273&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38273&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38273&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38273&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38273&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38273&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38273&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38273&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38273&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38273&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38273&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38273&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38273&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38273&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38273&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38273&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38273&r=mysqlcfg

Reply via email to