From: mathew at eisbox dot net
Operating system: Ubuntu
PHP version: 5.2.11
PHP Bug Type: Reproducible crash
Bug description: exec hangs on running self-daemonizing bash script
Description:
------------
The attached bash script, when called via shell_exec, exec, and friends,
reproducibly locks apache2 mpm and PHP. (Standard package from Ubuntu). ps
shows a defunct sh process under apache2, and apache2 is unresponsive until
the owning instance of apache2 is killed off.
When run from a shell, the script works without problems. (The script is
meant to fork and detach, the detached process runs another process as a
daemon)
This bug sounds similar to #44994, although this case is Linux, and
closing the session does not solve the problem. So I opened a new bug.
Reproduce code:
---------------
# This is a simplified version of a script designed to reproduce the
problem.
#!/bin/bash
DMNPATH=/path/to/dmn # Path to dmn
DMNARGS="-arga -argb" # Args to dmn
PIDFILE=/path/to/pid # keepalive pidfile
# Setup the keepalive (must be a function to fork)
function rundmn {
DMNPATH=$1
DMNARGS=$2
# Close stdin/stdout/stderr
0<&-; 1>&-; 2>&-
eval "$DMNPATH $DMNARGS"
}
# Check to see if we are already running
if [ -r $PIDFILE ] ; then
kill -0 `cat $PIDFILE` > /dev/null 2>&1
if [ $? -eq 0 ] ; then exit; fi
fi
# fork the rundmn func, save its PID, and detatch
rundmn "$DMNPATH" "$DMNARGS" &
PID=$!; echo $PID > $PIDFILE
disown $PID
Expected result:
----------------
I expect a call to exec to run the above bash script, which should return
control almost immediately to the PHP script, continuing execution of the
PHP script.
Actual result:
--------------
When run from PHP's exec, the bash script is behaving as expected, and
executes to completion as expected. (I have verified execution to a point
beyond the last disown command) However, no PHP code beyond the exec is
run, and apache2 appears locked. I am uncertain how to proceed beyond this
point.
--
Edit bug report at http://bugs.php.net/?id=50011&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=50011&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=50011&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=50011&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=50011&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=50011&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=50011&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=50011&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=50011&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=50011&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=50011&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=50011&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=50011&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=50011&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=50011&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50011&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50011&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=50011&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=50011&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=50011&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=50011&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=50011&r=mysqlcfg