vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
|
215f8aeb
Keenan Nemetz
2d ago
|
1 | //go:build unix |
| 2 | ||
| 3 | package agent | |
| 4 | ||
| 5 | import ( | |
| 6 | "os" | |
| 7 | "syscall" | |
| 8 | ) | |
| 9 | ||
| 10 | // lockExclusive takes the saved checkout's exclusive lock, waiting unless | |
| 11 | // nonBlocking is set. flock releases the lock when the descriptor closes, | |
| 12 | // including when the process is killed, so a runner that dies mid-repack leaves | |
| 13 | // nothing a later run has to clean up. | |
| 14 | func lockExclusive(f *os.File, nonBlocking bool) error { | |
| 15 | how := syscall.LOCK_EX | |
| 16 | if nonBlocking { | |
| 17 | how |= syscall.LOCK_NB | |
| 18 | } | |
| 19 | for { | |
| 20 | err := syscall.Flock(int(f.Fd()), how) | |
| 21 | if err == nil { | |
| 22 | return nil | |
| 23 | } | |
| 24 | // A signal can interrupt the wait; the lock is not held, so ask again. | |
| 25 | if err != syscall.EINTR { | |
| 26 | return err | |
| 27 | } | |
| 28 | } | |
| 29 | } | |
| 30 | ||
| 31 | // unlockFile releases the lock taken by lockExclusive. | |
| 32 | func unlockFile(f *os.File) error { | |
| 33 | return syscall.Flock(int(f.Fd()), syscall.LOCK_UN) | |
| 34 | } |