Req #70419 [Opn]: proc_close return code is unreliable
| From: | cmb@php.net | Date: | Thu, 25 Aug 2016 00:13:53 +0000 |
| Subject: | Req #70419 [Opn]: proc_close return code is unreliable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203528@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70419&edit=1
ID: 70419
Updated by: cmb@php.net
Reported by: uwe at ohse dot de
Summary: proc_close return code is unreliable
Status: Open
Type: Feature/Change Request
Package: Program Execution
Operating System: Unix
PHP Version: 7.0.0RC1
Block user comment: N
Private report: N
New Comment:
Unfortunately, it's too late for PHP 7.0, so some discussion would
have to happen whether this can go into 7.2 or would have to be
postponed until 8.0. A PR *might* help to start this discussion.
Previous Comments:
------------------------------------------------------------------------
[2015-09-03 12:02:25] uwe at ohse dot de
Description:
------------
The documentation of proc_close states that the function "Returns the termination status of the
process that was run. In case of an error then -1 is returned."
The documentation of pclose() goes even further and recommends to use pcntl_wexitstatus() in a (unix
only) note.
What the functions return can be seen in ext/standard/proc_open.c, proc_open_rsrc_dtor(), with
status being the status parameter of waitpid:
if (WIFEXITED(wstatus))
wstatus = WEXITSTATUS(wstatus);
FG(pclose_ret) = wstatus;
The return code this is either the exitstatus of the process, if it didn't die by a signal, or
the status returned by waitpid, but the caller can't tell anymore, because exit(1) and a SIGHUP
are both mapped to 1.
This reduces the value of the exit code to a trinary (-1, 0, all other).
I propose to fix this mess by:
1) remove the first two lines above in PHP 7 (do it fast, do it *now*), and
2) document that the return code of the two functions is unusable before that, and
3) document that the return code has to be treated the very same as the status parameter of waitpid
(unless an error happened, of course), and
4) remove the note in pclose, and
5) have someone with windows knowledge look into it, too.
That might be seen as breaking backwards compatibility, but code using the exit status of the two
functions is broken anyway.
If the proposed change can or will not be done, then at least please document the current behaviour
clearly, as any misunderstanding can cause a very inappropriate error handling.
This problem has been reported already (#53518) in 2010 for PHP 5.3. I report it again because PHP 7
seems to be a very good point to change the behaviour, and because the documentation should be
changed.
Test script:
---------------
<?php
$p1 = proc_open ("exit 1", array(), $pipes);
$x1 = proc_close($p1);
print "$x1\n";
$p2 = proc_open ('kill -HUP $$', array(), $pipes);
$x2 = proc_close($p2);
print "$x2\n";
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70419&edit=1