#!/bin/sh

. $(dirname $0)/testsuite-common.sh

setup_test

run_daemon

# wait a while for the pid file to show up
limit=20
while [ ! -f "${pidfile}" -a 0 -ne "$limit" ] ; do
    sleep 1
    limit=$(($limit - 1))
done

if [ -f "${pidfile}" ]; then
    waittime=$((20 - $limit))
    echo "success: found pid file ${pidfile} (took $waittime seconds)"
else
    fail "missing pid file ${pidfile} (gave up after 20 seconds)"
fi

kill "$(cat ${pidfile})"

sleep 2

if [ ! -f "${pidfile}" ]; then
    echo "success: pid file ${pidfile} no longer present"
else
    fail "found obsolete pid file ${pidfile}"
fi

cleanup_test

#!/bin/sh

. $(dirname $0)/testsuite-common.sh

setup_test

run_daemon

# wait for the pid file to appear
limit=20
while [ ! -s "${pidfile}" ] ; do
	[ $((elapsed+=1)) -lt $limit ] ||
		fail "timed out waiting for pid file to appear"
	sleep 1
done
notice "pid file appeared after $elapsed seconds"

# kill tsdfx
kill "$(cat ${pidfile})"
notice "killed daemon"

# wait for the pid file to vanish
limit=20
while [ -s "${pidfile}" ] ; do
	[ $((elapsed+=1)) -lt $limit ] ||
		fail "timed out waiting for pid file to vanish"
	sleep 1
done
notice "pid file vanished after $elapsed seconds"

cleanup_test

Rewrite pidfile test so it waits until the file is non-empty. Otherwise, it might try to read it before tsdfx had written its pid to it.
Rewrite pidfile test so it waits until the file is non-empty.  Otherwise, it might try to read it before tsdfx had written its pid to it.
