fix set -e

This commit is contained in:
Urban Modig
2025-10-01 11:55:01 +02:00
parent c93104874b
commit 57fcdef4fe

View File

@ -43,7 +43,14 @@ LOCK_HELD=0
lock() { lock() {
log "Creating lock… ($LOCK_FILE)" log "Creating lock… ($LOCK_FILE)"
exec ${LOCK_FD}>"$LOCK_FILE" || die "Could not open lock file $LOCK_FILE" # Use a literal FD number for portability: exec 200>"$LOCK_FILE"
exec 200>"$LOCK_FILE" || die "Could not open lock file $LOCK_FILE"
if flock -n 200; then
LOCK_HELD=1
else
die "Lock failed — another process is running."
fi
}>"$LOCK_FILE" || die "Could not open lock file $LOCK_FILE"
if flock -n ${LOCK_FD}; then if flock -n ${LOCK_FD}; then
LOCK_HELD=1 LOCK_HELD=1
else else
@ -54,7 +61,12 @@ lock() {
unlock() { unlock() {
if (( LOCK_HELD )); then if (( LOCK_HELD )); then
log "Releasing lock…" log "Releasing lock…"
flock -u ${LOCK_FD} || true flock -u 200 || true
# Close the FD to avoid lingering descriptors
exec 200>&- || true
LOCK_HELD=0
fi
} || true
# Close the FD to avoid lingering descriptors # Close the FD to avoid lingering descriptors
exec ${LOCK_FD}>&- || true exec ${LOCK_FD}>&- || true
LOCK_HELD=0 LOCK_HELD=0
@ -351,4 +363,3 @@ fi
# cleanup happens via trap # cleanup happens via trap
exit 0 exit 0