Re: SEGV support for run-tests
| From: | Ferenc Kovacs | Date: | Thu, 03 Jul 2014 11:59:33 +0000 |
| Subject: | Re: SEGV support for run-tests | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75226@lists.php.net to get a copy of this message | ||
thanks for the explanation.
judging by the comments, this change of behavior isn't really intended (and
it breaks $data .= "\nTermsig=" . $stat['stopsig'];) but was used to unset
some environment variables instead of using the env parameter for
proc_open, which is already moot as we use the env argument for proc_open.
I would suggest removing the unsets from the command(and the !== "WIN"
check) and that would already turn the segfaulting tests to failures
without any further patching.
On Thu, Jul 3, 2014 at 1:36 PM, Michael Wallner <mike@php.net> wrote:
> Because the shell forks again (apparently in batch mode) to exec php and
> returncodes >128 is how the shell reports term by signals:
>
> proc_open("php"):
> - php: fork()
> - php: exec("sh -c 'php ...'")
> - sh: exec("php ...")
> - php: I'm the child
> - php: wait()
> The child is PHP, we get all the good proc_status.
>
> proc_open("unset foo; php")
> - php: fork()
> - php: exec("sh -c 'unset foo; php ...'")
> - sh: fork()
> - sh: exec("php")
> - php: I'm the grand child
> - sh: wait()
> - sh: exit(128+signo)
> - php: wait()
> PHP was actually the grand child and we end up with the signo in the
> returncode of our child, the shell.
>
>
>
> On 3 July 2014 13:06, Ferenc Kovacs <tyrael@php.net> wrote:
>
>> hm, how does that work?
>> I can comfirm that we indeed end up with 128+signum exit code, I just
>> fail to see why.
>>
>>
>> On Thu, Jul 3, 2014 at 12:19 PM, Michael Wallner <mike@php.net> wrote:
>>
>>> Now I see; run-tests does several "unset foo;" before the actual
>>> command, we end up with the signo(+128) as exitcode of the shell.
>>>
>>>
>>> On 3 July 2014 12:05, Michael Wallner <mike@php.net> wrote:
>>>
>>>> Your case is actually already be handled by run-tests:
>>>> Termsig=11 sould be appended to the test's output.
>>>>
>>>> if ($stat['signaled']) {
>>>> $data .= "\nTermsig=" . $stat['stopsig'];
>>>> }
>>>>
>>>>
>>>> On 3 July 2014 11:57, Michael Wallner <mike@php.net> wrote:
>>>>
>>>>> Seems about true. I wonder why that's not the case in the run-tests
>>>>> environment...
>>>>>
>>>>>
>>>>> On 3 July 2014 11:40, Ferenc Kovacs <tyrael@php.net> wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thu, Jul 3, 2014 at 11:23 AM, Michael Wallner <mike@php.net>
>>>>>> wrote:
>>>>>>
>>>>>>> On 3 July 2014 11:18, Ferenc Kovacs <tyrael@php.net> wrote:
>>>>>>>
>>>>>>>> hi,
>>>>>>>>
>>>>>>>> I think the patch is wrong.
>>>>>>>> from my experience, when a proc_opened process is killed via a
>>>>>>>> signal (before you had a chance to proc_close() it) then the
>>>>>>>> exitcode
>>>>>>>> reported by proc_close() and proc_get_status() will be -1, but
>>>>>>>> proc_get_status()["signaled"] will be true and
>>>>>>>> proc_get_status()["termsig"]
>>>>>>>> will have the signalcode of the signal which terminated the
>>>>>>>> process(11 for
>>>>>>>> sigsegv).
>>>>>>>>
>>>>>>>
>>>>>>> This worked:
>>>>>>>
>>>>>>> --TEST--
>>>>>>> segfault
>>>>>>> --SKIPIF--
>>>>>>> <?php extension_loaded("posix") or die("skip need
>>>>>>> posix\n");
>>>>>>> --FILE--
>>>>>>> <?php
>>>>>>> echo "before\n";
>>>>>>> posix_kill(posix_getpid(),11);
>>>>>>> echo "after\n";
>>>>>>> ?>
>>>>>>> ===DONE===
>>>>>>> --EXPECTF--
>>>>>>> before
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Regards,
>>>>>>> Mike
>>>>>>>
>>>>>>
>>>>>> [tyrael@Ferencs-MacBook-Pro-135 php-src.git (PHP-5.4 ✗)]$ cat
>>>>>> test.php
>>>>>> <?php
>>>>>> $descriptorspec = array(
>>>>>> 0 => array("pipe", "r"), // stdin is a pipe that
>>>>>> the child will
>>>>>> read from
>>>>>> 1 => array("pipe", "w"), // stdout is a pipe
>>>>>> that the child will
>>>>>> write to
>>>>>> 2 => array("file", "/tmp/error-output.txt",
>>>>>> "a") // stderr is a
>>>>>> file to write to
>>>>>> );
>>>>>>
>>>>>> $cwd = '/tmp';
>>>>>> $env = array();
>>>>>>
>>>>>> $process = proc_open(PHP_BINARY.'
>>>>>> '.__DIR__.'/test2.php',
>>>>>> $descriptorspec, $pipes, $cwd, $env);
>>>>>> sleep(1);
>>>>>> $status = proc_get_status($process);
>>>>>> $exitCode = proc_close($process);
>>>>>> var_dump($exitCode);
>>>>>> var_dump($status);
>>>>>> [tyrael@Ferencs-MacBook-Pro-135 php-src.git (PHP-5.4 ✗)]$ cat
>>>>>> test2.php
>>>>>> <?php
>>>>>> echo "before\n";
>>>>>> posix_kill(posix_getpid(),11);
>>>>>> echo "after\n";
>>>>>> ?>
>>>>>> [tyrael@Ferencs-MacBook-Pro-135 php-src.git (PHP-5.4 ✗)]$
>>>>>> ./sapi/cli/php test.php
>>>>>> int(-1)
>>>>>> array(8) {
>>>>>> ["command"]=>
>>>>>> string(94) "/Users/tyrael/checkouts/php-src.git/sapi/cli/php
>>>>>> /Users/tyrael/checkouts/php-src.git/test2.php"
>>>>>> ["pid"]=>
>>>>>> int(9158)
>>>>>> ["running"]=>
>>>>>> bool(false)
>>>>>> ["signaled"]=>
>>>>>> bool(true)
>>>>>> ["stopped"]=>
>>>>>> bool(false)
>>>>>> ["exitcode"]=>
>>>>>> int(-1)
>>>>>> ["termsig"]=>
>>>>>> int(11)
>>>>>> ["stopsig"]=>
>>>>>> int(0)
>>>>>> }
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Regards,
>>>>> Mike
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Regards,
>>>> Mike
>>>>
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Mike
>>>
>>
>>
>
>
> --
> Regards,
> Mike
>