Revision 7429
Added by Aaron Marcuse-Kubitza almost 12 years ago
bin/lockfile | ||
---|---|---|
6 | 6 |
|
7 | 7 |
: "${interval=5}" # s |
8 | 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 |
|
|
9 | 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 |
|
10 | 25 |
while ! shlock -p "$PPID" -f "$1"; do sleep "$interval"; done |
11 | 26 |
else |
12 |
exec "$selfDir/dotlockfile" -l -r 65535 -p "$1" # exec to inherit PPID |
|
27 |
export SHELL="$0" inner=1 pid="$PPID" |
|
28 |
newgrp "$(file_group "$(dirname -- "$lockfile")")" |
|
13 | 29 |
fi |
Also available in: Unified diff
lockfile: Linux: Fixed bug where need to change primary group of the dotlockfile process to the group of the dir to contain the lockfile, because dotlockfile otherwise reports a "permission denied" error (even though the directory is actually writable, dotlockfile thinks it isn't). Running dotlockfile with a different primary group is complicated because newgrp, the command that does this, does not pass arguments to the new process, so they must instead be passed via environment variables and a recursive invocation of lockfile (with the $inner recursion flag set). Additionally, exec cannot be used to propagate the PPID (needed by dotlockfile) because newgrp creates a new process rather than using exec, so it must be manually entered into the lockfile after dotlockfile runs.