mirror of
https://github.com/rclone/rclone.git
synced 2024-11-30 04:23:48 +08:00
41 lines
679 B
Go
41 lines
679 B
Go
|
// +build solaris
|
||
|
|
||
|
package daemon
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"syscall"
|
||
|
)
|
||
|
|
||
|
func lockFile(fd uintptr) error {
|
||
|
lockInfo := syscall.Flock_t{
|
||
|
Type: syscall.F_WRLCK,
|
||
|
Whence: io.SeekStart,
|
||
|
Start: 0,
|
||
|
Len: 0,
|
||
|
}
|
||
|
if err := syscall.FcntlFlock(fd, syscall.F_SETLK, &lockInfo); err != nil {
|
||
|
if err == syscall.EAGAIN {
|
||
|
err = ErrWouldBlock
|
||
|
}
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func unlockFile(fd uintptr) error {
|
||
|
lockInfo := syscall.Flock_t{
|
||
|
Type: syscall.F_UNLCK,
|
||
|
Whence: io.SeekStart,
|
||
|
Start: 0,
|
||
|
Len: 0,
|
||
|
}
|
||
|
if err := syscall.FcntlFlock(fd, syscall.F_GETLK, &lockInfo); err != nil {
|
||
|
if err == syscall.EAGAIN {
|
||
|
err = ErrWouldBlock
|
||
|
}
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|