paths, version/distro: detect Synology DSM version better, use for socket path

Resolves a TODO in the code noted while discussing QNAP defaults.

Tested on DSM6 and DSM7.

Change-Id: Icce03ff41fafd7b3a358cfee16f2ed13d5cc3c5d
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/6599/head
Brad Fitzpatrick 2 years ago committed by Brad Fitzpatrick
parent 5b8323509f
commit b9dd3fa534

@ -30,15 +30,11 @@ func DefaultTailscaledSocket() string {
} }
switch distro.Get() { switch distro.Get() {
case distro.Synology: case distro.Synology:
// TODO(maisem): be smarter about this. We can parse /etc/VERSION. if distro.DSMVersion() == 6 {
const dsm6Sock = "/var/packages/Tailscale/etc/tailscaled.sock" return "/var/packages/Tailscale/etc/tailscaled.sock"
const dsm7Sock = "/var/packages/Tailscale/var/tailscaled.sock"
if fi, err := os.Stat(dsm6Sock); err == nil && !fi.IsDir() {
return dsm6Sock
}
if fi, err := os.Stat(dsm7Sock); err == nil && !fi.IsDir() {
return dsm7Sock
} }
// DSM 7 (and higher? or failure to detect.)
return "/var/packages/Tailscale/var/tailscaled.sock"
case distro.Gokrazy: case distro.Gokrazy:
return "/perm/tailscaled/tailscaled.sock" return "/perm/tailscaled/tailscaled.sock"
} }

@ -6,11 +6,14 @@
package distro package distro
import ( import (
"bytes"
"io"
"os" "os"
"runtime" "runtime"
"strconv" "strconv"
"tailscale.com/syncs" "tailscale.com/syncs"
"tailscale.com/util/lineread"
) )
type Distro string type Distro string
@ -97,6 +100,8 @@ func freebsdDistro() Distro {
return "" return ""
} }
var dsmVersion syncs.AtomicValue[int]
// DSMVersion reports the Synology DSM major version. // DSMVersion reports the Synology DSM major version.
// //
// If not Synology, it reports 0. // If not Synology, it reports 0.
@ -107,6 +112,30 @@ func DSMVersion() int {
if Get() != Synology { if Get() != Synology {
return 0 return 0
} }
if v, ok := dsmVersion.LoadOk(); ok && v != 0 {
return v
}
// This is set when running as a package:
v, _ := strconv.Atoi(os.Getenv("SYNOPKG_DSM_VERSION_MAJOR")) v, _ := strconv.Atoi(os.Getenv("SYNOPKG_DSM_VERSION_MAJOR"))
if v != 0 {
dsmVersion.Store(v)
return v
}
// But when run from the command line, we have to read it from the file:
lineread.File("/etc/VERSION", func(line []byte) error {
line = bytes.TrimSpace(line)
if string(line) == `majorversion="7"` {
v = 7
return io.EOF
}
if string(line) == `majorversion="6"` {
v = 6
return io.EOF
}
return nil
})
if v != 0 {
dsmVersion.Store(v)
}
return v return v
} }

Loading…
Cancel
Save