+#!/bin/sh
+#
+# testcase experimenting whether daemon --pidfile --fork --makepid works with RC_LOGGING=on and off
+#
+
+dir=$(readlink -f $(dirname "$0"))
+testname=$(basename "$0")
+# save flags, as want to load functions with set +x
+set=$-
+
+set +x
+. $dir/../lib/functions
+set -$set
+
+pidfile=$dir/$testname.pid
+makepid="$dir/../lib/makepid"
+# use /bin/sleep to avoid using sleep builtin
+testprog="/bin/sleep 300"
+
+# fail on errors
+set -e
+
+assert_pidfile() {
+ pid=$(cat $pidfile)
+ # pid must exist
+ test -n "$pid"
+
+ # command must match what was started
+ cmd=$(ps -o cmd= -p $pid)
+ test "$cmd" = "$testprog"
+}
+
+test_makepid() {
+ rm -f $pidfile
+ PIDFILE=$pidfile $makepid $testprog
+ assert_pidfile
+}
+
+test_daemon() {
+ rm -f $pidfile
+ daemon --pidfile $pidfile --fork --makepid $testprog
+ assert_pidfile
+}
+
+test_makepid
+
+RC_LOGGING=yes
+test_daemon
+
+RC_LOGGING=no
+test_daemon