+# inner function used by daemon().
+# do not call this directly, as it expects variables being inherited.
+# also it expects to be called from subshell as it exports env.
+# it expects options parsed by daemon() and command to be executed in "$@".
+_daemon_exec() {
+ local prog=""
+ umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK};
+ export USER=root HOME=/tmp TMPDIR=/tmp
+
+ nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL}
+ nice=${nice:-0}
+
+ # make nice level absolute, not to be dependant of nice level of shell where service started
+ nice=$(($nice - $(nice)))
+
+ if [ "$closefds" = 1 ]; then
+ exec 1>&-
+ exec 2>&-
+ exec 0<&-
+ elif [ "$redirfds" = 1 ]; then
+ exec 1>/dev/null
+ exec 2>/dev/null
+ exec 0</dev/null
+ else
+ exec 2>&1
+ exec 0</dev/null
+ fi
+
+ if is_no "$RC_LOGGING"; then
+ prog=$1; shift
+ if [ ! -x $prog ]; then
+ logger -t rc-scripts -p daemon.debug "daemon: Searching PATH for $prog, consider using full path in initscript"
+ local a o=$IFS
+ IFS=:
+ for a in $PATH; do
+ if [ -x $a/$prog ]; then
+ prog=$a/$prog
+ break
+ fi
+ done
+ IFS=$o
+ fi
+ set -- "$prog" "$@"
+
+ # use setsid to detach from terminal,
+ # NOTE: setsid needs to be "outer" program
+ # otherwise start-stop-daemon would capture the setsid pid not the actual program
+
+ prog=$1; shift
+ /usr/bin/setsid \
+ /sbin/start-stop-daemon -q --start \
+ --nicelevel $nice \
+ ${pidfile:+--pidfile $pidfile} \
+ ${makepid:+--make-pidfile} \
+ ${user:+--chuid $user} \
+ ${chdir:+--chdir "$chdir"} \
+ ${fork:+--background} \
+ ${SERVICE_DROPCAPS:+--dropcap $SERVICE_DROPCAPS} \
+ --exec "$prog" \
+ -- "$@"
+ else
+ if [ "$fork" = "1" ]; then
+ export PIDFILE="/dev/null"
+ if [ "$makepid" ] && [ "$pidfile" ]; then
+ export PIDFILE="$pidfile"
+ fi
+ set -- /lib/rc-scripts/makepid "$@"
+ set -- /usr/bin/setsid "$@"
+ fi
+ if [ -n "$user" -a "$user" != "root" ]; then
+ set -- /bin/runuser -u "$user" -- "$@"
+ fi
+
+ nice -n $nice initlog -c "$*" 2>&1 </dev/null
+ fi
+}
+