]>
Commit | Line | Data |
---|---|---|
43f8f34f ER |
1 | #!/bin/sh |
2 | # | |
3 | # testcase experimenting whether daemon --pidfile --fork --makepid works with RC_LOGGING=on and off | |
4 | # | |
5 | ||
6 | dir=$(readlink -f $(dirname "$0")) | |
7 | testname=$(basename "$0") | |
8 | # save flags, as want to load functions with set +x | |
9 | set=$- | |
10 | ||
11 | set +x | |
12 | . $dir/../lib/functions | |
13 | set -$set | |
14 | ||
15 | pidfile=$dir/$testname.pid | |
16 | makepid="$dir/../lib/makepid" | |
17 | # use /bin/sleep to avoid using sleep builtin | |
18 | testprog="/bin/sleep 300" | |
19 | ||
20 | # fail on errors | |
21 | set -e | |
22 | ||
23 | assert_pidfile() { | |
24 | pid=$(cat $pidfile) | |
25 | # pid must exist | |
26 | test -n "$pid" | |
27 | ||
28 | # command must match what was started | |
29 | cmd=$(ps -o cmd= -p $pid) | |
30 | test "$cmd" = "$testprog" | |
31 | } | |
32 | ||
33 | test_makepid() { | |
34 | rm -f $pidfile | |
35 | PIDFILE=$pidfile $makepid $testprog | |
36 | assert_pidfile | |
37 | } | |
38 | ||
39 | test_daemon() { | |
40 | rm -f $pidfile | |
41 | daemon --pidfile $pidfile --fork --makepid $testprog | |
42 | assert_pidfile | |
43 | } | |
44 | ||
45 | test_makepid | |
46 | ||
47 | RC_LOGGING=yes | |
48 | test_daemon | |
49 | ||
50 | RC_LOGGING=no | |
51 | test_daemon |