#38273 [Fbk->Opn]: Incorrect return address after the execution of a signal handler?

From: Date: Tue, 01 Aug 2006 11:59:15 +0000
Subject: #38273 [Fbk->Opn]: Incorrect return address after the execution of a signal handler?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-100174@lists.php.net to get a copy of this message
 ID:               38273
 User updated by:  axelluttgens at swing dot be
 Reported By:      axelluttgens at swing dot be
-Status:           Feedback
+Status:           Open
 Bug Type:         PCNTL related
 Operating System: Mac OS 10.4.7
 PHP Version:      4.4.2
 New Comment:

Hello Tony, thanks again for your follow up!

For various reasons, I am currently really stuck with PHP 4 here. In
that sense, PHP 5 isn't an alternative for me yet.

But perhaps were you considering a very precise point?
Do you want me to try something else?

TIA,
Axel


Previous Comments:
------------------------------------------------------------------------

[2006-07-31 20:13:53] tony2001@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip



------------------------------------------------------------------------

[2006-07-31 19:40:17] axelluttgens at swing dot be

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 this bug report at http://bugs.php.net/?id=38273&edit=1


Thread (12 messages)

« previous php.bugs (#100174) next »