mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
cb2e9119aa
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
//go:build !windows
|
|
// +build !windows
|
|
|
|
package statemgr
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"syscall"
|
|
)
|
|
|
|
// use fcntl POSIX locks for the most consistent behavior across platforms, and
|
|
// hopefully some campatibility over NFS and CIFS.
|
|
func (s *Filesystem) lock() error {
|
|
log.Printf("[TRACE] statemgr.Filesystem: locking %s using fcntl flock", s.path)
|
|
flock := &syscall.Flock_t{
|
|
Type: syscall.F_RDLCK | syscall.F_WRLCK,
|
|
Whence: int16(io.SeekStart),
|
|
Start: 0,
|
|
Len: 0,
|
|
}
|
|
|
|
fd := s.stateFileOut.Fd()
|
|
return syscall.FcntlFlock(fd, syscall.F_SETLK, flock)
|
|
}
|
|
|
|
func (s *Filesystem) unlock() error {
|
|
log.Printf("[TRACE] statemgr.Filesystem: unlocking %s using fcntl flock", s.path)
|
|
flock := &syscall.Flock_t{
|
|
Type: syscall.F_UNLCK,
|
|
Whence: int16(io.SeekStart),
|
|
Start: 0,
|
|
Len: 0,
|
|
}
|
|
|
|
fd := s.stateFileOut.Fd()
|
|
return syscall.FcntlFlock(fd, syscall.F_SETLK, flock)
|
|
}
|