Project

General

Profile

1
#!/bin/sh
2
# Wraps lockfile/dotlockfile
3
# Usage: env [interval=...] self lockfile
4

    
5
selfDir="$(dirname -- "$0")"
6

    
7
: "${interval=5}" # s
8

    
9
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
if test "$(uname)" = Darwin; then
18
    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
    while ! shlock -p "$PPID" -f "$1"; do sleep "$interval"; done
26
else
27
    export SHELL="$0" inner=1 pid="$PPID"
28
    newgrp "$(file_group "$(dirname -- "$lockfile")")"
29
fi
(37-37/76)