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