mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-04 06:31:54 +00:00
paths: use /var/db for state on BSDs, and /var/run for sockets.
On BSD, /var/db is what linux calls /var/lib. On modern linux, /run and /var/run are the same directory, but on BSD the correct path is /var/run, so use that. Fixes #79 Signed-off-by: David Anderson <dave@natulte.net>
This commit is contained in:
parent
20da44eae3
commit
dbc99dc0d2
@ -21,8 +21,8 @@ func DefaultTailscaledSocket() string {
|
|||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
if fi, err := os.Stat("/run"); err == nil && fi.IsDir() {
|
if fi, err := os.Stat("/var/run"); err == nil && fi.IsDir() {
|
||||||
return "/run/tailscale/tailscaled.sock"
|
return "/var/run/tailscale/tailscaled.sock"
|
||||||
}
|
}
|
||||||
return "tailscaled.sock"
|
return "tailscaled.sock"
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ package paths
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
@ -16,14 +17,28 @@ func init() {
|
|||||||
stateFileFunc = stateFileUnix
|
stateFileFunc = stateFileUnix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func statePath() string {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
return "/var/lib/tailscale/tailscaled.state"
|
||||||
|
case "freebsd", "openbsd":
|
||||||
|
return "/var/db/tailscale/tailscaled.state"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func stateFileUnix() string {
|
func stateFileUnix() string {
|
||||||
// TODO: use other default paths on other GOOSes probably. This works for Linux.
|
path := statePath()
|
||||||
const varLib = "/var/lib/tailscale/tailscaled.state"
|
if path == "" {
|
||||||
try := varLib
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
try := path
|
||||||
for i := 0; i < 3; i++ { // check writability of the file, /var/lib/tailscale, and /var/lib
|
for i := 0; i < 3; i++ { // check writability of the file, /var/lib/tailscale, and /var/lib
|
||||||
err := unix.Access(try, unix.O_RDWR)
|
err := unix.Access(try, unix.O_RDWR)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return varLib
|
return path
|
||||||
}
|
}
|
||||||
try = filepath.Dir(try)
|
try = filepath.Dir(try)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user