diff options
Diffstat (limited to 'tests/aux/respawn')
-rwxr-xr-x | tests/aux/respawn | 75 |
1 files changed, 17 insertions, 58 deletions
diff --git a/tests/aux/respawn b/tests/aux/respawn index cd9687a..afed85b 100755 --- a/tests/aux/respawn +++ b/tests/aux/respawn | |||
@@ -2,62 +2,21 @@ | |||
2 | 2 | ||
3 | # usage: respawn [-append] [-stderr FILE] [-stdout FILE] [-sleep TIME] | 3 | # usage: respawn FILE COUNT |
4 | # [-pid FILE] [-tag STRING] [-exit CODE] | ||
5 | 4 | ||
6 | append=0 | 5 | file=${1:?} |
7 | unset name | 6 | maxcount=${2:?} |
8 | time=1 | ||
9 | tag=$0 | ||
10 | code=0 | ||
11 | 7 | ||
12 | while [ $# -ne 0 ] | 8 | count=0 |
13 | do | ||
14 | arg=$1 | ||
15 | shift | ||
16 | case $arg in | ||
17 | -append) | ||
18 | append=1;; | ||
19 | -stderr) | ||
20 | name=${1:?missing argument for -stderr} | ||
21 | shift | ||
22 | if [ $append -eq 1 ]; then | ||
23 | exec 2>>$name | ||
24 | append=0 | ||
25 | else | ||
26 | exec 2>$name | ||
27 | fi;; | ||
28 | -stdout) | ||
29 | name=${1:?missing argument for -stdout} | ||
30 | shift | ||
31 | if [ $append -eq 1 ]; then | ||
32 | exec >>$name | ||
33 | append=0 | ||
34 | else | ||
35 | exec >$name | ||
36 | fi;; | ||
37 | -sleep) | ||
38 | time=${1:?missing argument for -sleep} | ||
39 | shift;; | ||
40 | -pid) | ||
41 | name=${1:?missing argument for -pid} | ||
42 | shift | ||
43 | if [ $append -eq 1 ]; then | ||
44 | echo $$ >>$name | ||
45 | append=0 | ||
46 | else | ||
47 | echo $$ >$name | ||
48 | fi;; | ||
49 | -tag) | ||
50 | tag=${1:?missing argument for -tag} | ||
51 | shift;; | ||
52 | -exit) | ||
53 | code=${1:?missing argument for -exit} | ||
54 | shift;; | ||
55 | *) echo >&2 "$tag: invalid argument: $arg" | ||
56 | exit 1 | ||
57 | esac | ||
58 | done | ||
59 | 9 | ||
60 | echo "$tag: start" | 10 | if [ -f $file ]; then |
61 | sleep $time | 11 | count=`cat $file` |
62 | echo "$tag: stop" | 12 | if test -n "$count" && test $count -ge $maxcount; then |
63 | exit $code | 13 | exit 1 |
14 | fi | ||
15 | fi | ||
16 | |||
17 | count=$(($count + 1)) | ||
18 | echo "$count" > $file | ||
19 | |||
20 | exit 0 | ||
21 | |||
22 | |||