Subject: Add an option to safe_asterisk so that it won't background.
Author: Faidon Liambotis <paravoid@debian.org>
Bug-Debian: http://bugs.debian.org/376514
Forwarded: not-needed
Last-Update: 2010-10-21

This is intended to work with start-stop-daemon's --background option which
results in a correct pidfile since the process doesn't fork.

Needs more work from me to not change behavior for users but only for the
init script. After that, it can safely go upstream.

--- a/contrib/scripts/safe_asterisk
+++ b/contrib/scripts/safe_asterisk
@@ -14,6 +14,7 @@ SLEEPSECS=4
 ASTSBINDIR=__ASTERISK_SBIN_DIR__
 ASTVARRUNDIR=__ASTERISK_VARRUN_DIR__
 ASTPIDFILE=${ASTVARRUNDIR}/asterisk.pid
+SAFE_AST_BACKGROUND=0
 
 # comment this line out to have this script _not_ kill all mpg123 processes when
 # asterisk exits
@@ -197,4 +198,8 @@ run_asterisk()
 	done
 }
 
-run_asterisk &
+if [ "$SAFE_AST_BACKGROUND" = "1" ]; then
+	run_asterisk &
+else
+	run_asterisk
+fi
