File: lock_file_solaris.go

package info (click to toggle)
golang-github-sevlyar-go-daemon 0.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 232 kB
  • sloc: makefile: 3
file content (40 lines) | stat: -rw-r--r-- 679 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// +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
}