1 |
7259
|
aaronmk
|
#!/bin/sh
|
2 |
|
|
# Wraps lockfile/dotlockfile
|
3 |
7260
|
aaronmk
|
# Usage: env [interval=...] self lockfile
|
4 |
7259
|
aaronmk
|
|
5 |
7426
|
aaronmk
|
selfDir="$(dirname -- "$0")"
|
6 |
|
|
|
7 |
7262
|
aaronmk
|
: "${interval=5}" # s
|
8 |
7260
|
aaronmk
|
|
9 |
7429
|
aaronmk
|
if test -n "$inner"; then
|
10 |
|
|
"$selfDir/dotlockfile" -l -r 65535 -p "$lockfile" || exit
|
11 |
|
|
echo "$pid" >"$lockfile" # use the outer process's PPID
|
12 |
|
|
exit
|
13 |
|
|
fi
|
14 |
|
|
|
15 |
|
|
statFmtFlag="$(test "$(uname)" = Darwin && echo f || echo c)"
|
16 |
|
|
|
17 |
7260
|
aaronmk
|
if test "$(uname)" = Darwin; then
|
18 |
7429
|
aaronmk
|
file_group () { stat -f %Sg "$@"; }
|
19 |
|
|
else
|
20 |
|
|
file_group () { stat -c %G "$@"; }
|
21 |
|
|
fi
|
22 |
|
|
|
23 |
|
|
export lockfile="$1"
|
24 |
|
|
if test "$(uname)" = Darwin; then
|
25 |
7260
|
aaronmk
|
while ! shlock -p "$PPID" -f "$1"; do sleep "$interval"; done
|
26 |
|
|
else
|
27 |
7429
|
aaronmk
|
export SHELL="$0" inner=1 pid="$PPID"
|
28 |
|
|
newgrp "$(file_group "$(dirname -- "$lockfile")")"
|
29 |
7260
|
aaronmk
|
fi
|