waveterm/pkg/wavebase/wavebase-posix.go
Evan Simkowitz b51ff834b2
Happy new year! (#1684)
Update all 2024 references to 2025
2025-01-04 20:56:57 -08:00

31 lines
608 B
Go

// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
//go:build !windows
package wavebase
import (
"log"
"os"
"path/filepath"
"golang.org/x/sys/unix"
)
func AcquireWaveLock() (FDLock, error) {
dataHomeDir := GetWaveDataDir()
lockFileName := filepath.Join(dataHomeDir, WaveLockFile)
log.Printf("[base] acquiring lock on %s\n", lockFileName)
fd, err := os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return nil, err
}
err = unix.Flock(int(fd.Fd()), unix.LOCK_EX|unix.LOCK_NB)
if err != nil {
fd.Close()
return nil, err
}
return fd, nil
}