]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/sendmail/libsmutil/t-lockfile-0.sh
zfs: merge openzfs/zfs@887a3c533
[FreeBSD/FreeBSD.git] / contrib / sendmail / libsmutil / t-lockfile-0.sh
1 #!/bin/sh
2 # Copyright (c) 2021 Proofpoint, Inc. and its suppliers.
3 #       All rights reserved.
4 #
5 # By using this file, you agree to the terms and conditions set
6 # forth in the LICENSE file which can be found at the top level of
7 # the sendmail distribution.
8 #
9 # ----------------------------------------
10 # test t-lockfile, analyze result
11 # ----------------------------------------
12
13 fail()
14 {
15   echo "$0: $@"
16   exit 1
17 }
18
19 PRG=./t-lockfile
20 O=l.log
21
22 analyze()
23 {
24  # the "owner" unlock operation must be before
25  # the "client" lock operation can succeed
26  U=`grep -n 'owner=1, unlock.*done' $O | cut -d: -f1 | head -n1`
27  [ x"$U" = "x" ] && U=`grep -n '_close' $O | cut -d: -f1 | head -n1`
28  L=`grep -n 'owner=0, lock.* ok' $O | cut -d: -f1`
29  [ x"$U" = "x" ] && return 1
30  [ x"$L" = "x" ] && return 1
31  [ $U -lt $L ]
32 }
33
34 all=true
35 while getopts 2a: FLAG
36 do
37   case "${FLAG}" in
38     2) all=false;;
39     a) O=${OPTARG}
40        analyze || fail "$opts: unlock1=$U, lock2=$L"
41        exit;;
42   esac
43 done
44 shift `expr ${OPTIND} - 1`
45
46 [ -x ${PRG} ] || fail "missing ${PRG}"
47
48 if $all
49 then
50 for opts in "" "-r" "-n" "-nr"
51 do
52   ${PRG} $opts > $O 2>&1 || fail "$opts: $?"
53   analyze || fail "$opts: unlock1=$U, lock2=$L"
54 done
55 fi
56
57 # try with two processes
58 for opts in "" "-r"
59 do
60 rm -f $O
61 ${PRG} -W >> $O 2>&1 || fail "-W: $?"
62 wpid=$!
63 ${PRG} -R $opts >> $O 2>&1 || fail "-R $opts: $?"
64 rpid=$!
65 analyze || fail "$opts: unlock1=$U, lock2=$L"
66 wait $wpid
67 wait $rpid
68 done
69
70 exit 0