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>
pull/142/head
David Anderson 4 years ago committed by Dave Anderson
parent 20da44eae3
commit dbc99dc0d2

@ -21,8 +21,8 @@ func DefaultTailscaledSocket() string {
if runtime.GOOS == "windows" {
return ""
}
if fi, err := os.Stat("/run"); err == nil && fi.IsDir() {
return "/run/tailscale/tailscaled.sock"
if fi, err := os.Stat("/var/run"); err == nil && fi.IsDir() {
return "/var/run/tailscale/tailscaled.sock"
}
return "tailscaled.sock"
}

@ -8,6 +8,7 @@ package paths
import (
"path/filepath"
"runtime"
"golang.org/x/sys/unix"
)
@ -16,14 +17,28 @@ func init() {
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 {
// TODO: use other default paths on other GOOSes probably. This works for Linux.
const varLib = "/var/lib/tailscale/tailscaled.state"
try := varLib
path := statePath()
if path == "" {
return ""
}
try := path
for i := 0; i < 3; i++ { // check writability of the file, /var/lib/tailscale, and /var/lib
err := unix.Access(try, unix.O_RDWR)
if err == nil {
return varLib
return path
}
try = filepath.Dir(try)
}

Loading…
Cancel
Save