X-Git-Url: https://git.tld-linux.org/?p=rc-scripts.git;a=blobdiff_plain;f=t%2Fservice-fork-makepid.sh;fp=t%2Fservice-fork-makepid.sh;h=2426149e20f908fc3259c75f88adf0e013a69dab;hp=0000000000000000000000000000000000000000;hb=49ade4f4b5b1978db4561d62063008a339a1526f;hpb=2d25be2988d266692b556fbcc89c5b9108cf16f8 diff --git a/t/service-fork-makepid.sh b/t/service-fork-makepid.sh new file mode 100755 index 0000000..2426149 --- /dev/null +++ b/t/service-fork-makepid.sh @@ -0,0 +1,51 @@ +#!/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