| title | Single-instance flock for shell snipers | ||||||
|---|---|---|---|---|---|---|---|
| domain | ops | ||||||
| tags |
|
||||||
| status | published | ||||||
| lang | en | ||||||
| source | uncledad96-glitch | ||||||
| created | 2026-07-23 | ||||||
| updated | 2026-07-23 | ||||||
| confidence | 0.9 |
Two cron invocations of mm-snipe overlap and double-hit the same API.
No mutual exclusion around the critical section.
#!/usr/bin/env bash
set -euo pipefail
LOCK=${XDG_RUNTIME_DIR:-/tmp}/mm-snipe.lock
exec 9>"$LOCK"
if ! flock -n 9; then
echo "skip: another sniper holds lock"
exit 0
fi
# ... claim logic ...# terminal A
flock /tmp/t.lock -c 'sleep 30'
# terminal B should skip
flock -n /tmp/t.lock -c 'echo ran' || echo blocked- Pair with PID lockfiles in long-lived Python loops.
- Exit 0 on lock busy so cron does not alert spam.