]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/sendmail/libsmutil/t-maplock-0.sh
Merge llvm-project release/15.x llvmorg-15.0.0-9-g1c73596d3454
[FreeBSD/FreeBSD.git] / contrib / sendmail / libsmutil / t-maplock-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 map locking.
11 # Note: this is mostly for systems which use fcntl().
12 # just invoke it from the obj.*/libsmutil/ directory;
13 # otherwise use the -l and -m options to specify the paths.
14 # ----------------------------------------
15
16 fail()
17 {
18   echo "$0: $@"
19   exit 1
20 }
21
22 err()
23 {
24   echo "$0: $@"
25   rc=1
26 }
27
28 O=`basename $0`.0
29 V=vt
30 M=../makemap/makemap
31 CHKL=./t-lockfile
32
33 usage()
34 {
35   cat <<EOF
36 $0: test basic makemap locking;
37 requires `basename ${CHKL}` and `basename ${M}`.
38 usage:
39 $0 [options]
40 options:
41 -l locktest   path to `basename ${CHKL}` [default: ${CHKL}]
42 -m makemap    path to `basename ${M}` [default: $M]
43 EOF
44 }
45
46 tries=0
47 rc=0
48 while getopts l:m:t: FLAG
49 do
50   case "${FLAG}" in
51     l) CHKL="${OPTARG}";;
52     m) M="${OPTARG}";;
53     t) tries="${OPTARG}";;
54     *) usage
55         exit 69
56         ;;
57   esac
58 done
59 shift `expr ${OPTIND} - 1`
60
61 [ -x $M ] || fail "missing $M"
62 [ -x ${CHKL} ] || fail "missing ${CHKL}"
63
64 MAPTX=`$M -x | egrep 'hash|cdb'`
65
66 mm()
67 {
68   (echo "l1 l2"; sleep 5; echo "e1 e2") |
69   $M -v $MT $F >> $O 2>&1
70 }
71
72 chkl()
73 {
74   ${CHKL} -Rrc -f $F >> $O 2>&1
75 }
76
77 for XT in ${MAPTX}
78 do
79
80 MT=`echo $XT | cut -d: -f1`
81 EXT=`echo $XT | cut -d: -f2`
82
83 F=$V.${EXT}
84
85 rm -f $O
86 mm &
87 wpid=$!
88 sleep 1
89 chkl&
90 rpid=$!
91
92 while [ $tries -gt 0 ]
93 do
94   sleep 1; chkl
95   tries=`expr $tries - 1 `
96 done
97
98 wait $wpid
99 wait $rpid
100
101 if grep "status=unknown" $O >/dev/null
102 then
103   :
104 else
105   # get the makemap pid, not the "mm" pid, for checks?
106   grep "status=locked pid=" $O || err "$MT map not locked"
107 fi
108
109 done
110
111 exit $rc