Req #70419 [NEW]: proc_close return code is unreliable
| From: | uwe at ohse dot de | Date: | Thu, 03 Sep 2015 12:02:29 +0000 |
| Subject: | Req #70419 [NEW]: proc_close return code is unreliable | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-195734@lists.php.net to get a copy of this message | ||
From: uwe at ohse dot de
Operating system: Unix
PHP version: 7.0.0RC1
Package: Program Execution
Bug Type: Feature/Change Request
Bug description:proc_close return code is unreliable
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 bug report at https://bugs.php.net/bug.php?id=70419&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70419&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70419&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70419&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70419&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70419&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70419&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70419&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70419&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70419&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70419&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70419&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70419&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70419&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70419&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70419&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70419&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70419&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70419&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70419&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70419&r=mysqlcfg