From: james at jamesreno dot com Operating system: linux-2.6 PHP version: 5.2.9 PHP Bug Type: PCNTL related Bug description: PCNTL Waitpid exit status incorrect
Description: ------------ The $status exitcode returned by pcntl_waitpid() is incorrectly casted resulting in an invalid number being returned. I believe the int is converted to a long in ext/pcntl/pcntl.c, resulting in an invalid integer being returned to the parent. zval *z_status = NULL; int status; convert_to_long_ex(&z_status); status = Z_LVAL_P(z_status); child_id = waitpid((pid_t) pid, &status, options); Z_LVAL_P(z_status) = status; z_status is a long, but status is an int... Reproduce code: --------------- <? $pid = pcntl_fork(); if ($pid == -1) { echo "Unable to fork"; exit; } elseif ($pid) { $epid = pcntl_waitpid(-1,$status); echo "PARENT: {$pid}/{$epid} exited {$status}\n"; exit(128); } else { echo "CHILD: Exiting with exit code 128\n"; exit(128); } ?> Expected result: ---------------- [ja...@localhost ~]$ php test.php CHILD: Exiting with exit code 128 PARENT: 7598/7598 exited 128 [ja...@localhost ~]$ echo $? 128 [ja...@localhost ~]$ Actual result: -------------- [ja...@localhost ~]$ php test.php CHILD: Exiting with exit code 128 PARENT: 7598/7598 exited 32768 [ja...@localhost ~]$ echo $? 128 [ja...@localhost ~]$ -- Edit bug report at http://bugs.php.net/?id=47566&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47566&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47566&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47566&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47566&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47566&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47566&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47566&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47566&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47566&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47566&r=support Expected behavior: http://bugs.php.net/fix.php?id=47566&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47566&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47566&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47566&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47566&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47566&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47566&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47566&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47566&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47566&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47566&r=mysqlcfg