From: Operating system: Linux PHP version: trunk-SVN-2010-06-24 (SVN) Package: PCNTL related Bug Type: Feature/Change Request Bug description:ext/pcntl doesn't store/report errors
Description: ------------ The following ext/pcntl extensions "return -1 on failure", yet have multiple possible reasons for failure: pcntl_fork, pcntl_wait, pcntl_waitpid Each of these functions can fail for several reasons and in some cases (especially wait/waitpid) it is useful for the userland code to be able to handle the different error codes. The Linux man pages for fork(2) and wait/waitpid(2) all specify that the error code is stored in "errno" when an error occurs. I only have experience of the System V (Linux) way, so I'm not sure if this is interoperable, although I believe so. The ext/posix function posix_get_last_error() states that it returns the error code for the last posix function that failed. Internally, all of these functions also use "errno" to store the error code, but explicitly copy that to another variable, which posix_get_last_error() returns (http://lxr.php.net/opengrok/xref/PHP_5_2/ext/posix/posix.c#1167) I see two possible solutions, either: - posix_get_last_error() should be used to return these errors. Although this would add a dependency between the two extensions. - An optional parameter, &$errno, should be added to pcntl_fork(), pcntl_wait() and pcntl_waitpid() that is populated with errno if the result is -1. - A function is added to ext/pcntl, pcntl_get_last_error(), that operates in a similar way to posix_get_last_error(). The third option seems simplest and most compatible, although I can't help but feel these two extensions really belong together as one big happy family. What's the reason they're separate in the first place? Test script: --------------- <?php $pid = pcntl_wait($s); var_dump($pid, posix_get_last_error()); Expected result: ---------------- int(-1) int(10) # ECHILD Actual result: -------------- int(-1) int(0) -- Edit bug report at http://bugs.php.net/bug.php?id=52173&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52173&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52173&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52173&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52173&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52173&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52173&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52173&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52173&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52173&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52173&r=support Expected behavior: http://bugs.php.net/fix.php?id=52173&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52173&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52173&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52173&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52173&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52173&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52173&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52173&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52173&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52173&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52173&r=mysqlcfg