s6
Software
skarnet.org
The s6-setlock program
s6-setlock takes a lock on a file, then executes into another program.
Interface
s6-setlock [ -n | -N | -t timeout ] [ -r | -w ] file prog...
- s6-setlock creates file if it does not exist and opens it for writing.
- It locks file. If it cannot take the lock for any reason, it exits 1.
- It executes into prog....
Options
- -n : nonblocking lock. If s6-setlock cannot acquire the lock, it will
exit 1 immediately.
- -N : blocking lock. s6-setlock will wait until it can acquire the lock.
This is the default.
- -t timeout : timed lock. If s6-setlock cannot acquire
the lock after timeout milliseconds, it will exit 1.
- -r : shared lock. Other shared locks on the same file will not prevent
the lock from being acquired (but an exclusive lock will).
- -w : exclusive lock. This is the default.
Notes
- s6-setlock leaks an open file descriptor into the prog
execution. This is intended: the fd holds the lock, which is released
when prog exits. prog must not touch fds it does not
know about.
- If the timed lock option is chosen, s6-setlock does not acquire the lock
itself. Instead, it spawns a s6lockd-helper
process that acquires the lock while s6-setlock controls the timeout; the
s6lockd-helper process then holds the lock and lives as long as
prog.