mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-22 02:50:42 +00:00
hostinfo, tailcfg: split Hostinfo.OSVersion into separate fields
Stop jamming everything into one string. Fixes #5578 Change-Id: I7dec8d6c073bddc7dc5f653e3baf2b4bf6b68378 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
708b7bff3d
commit
d5e7e3093d
@@ -8,48 +8,58 @@
|
||||
package hostinfo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"tailscale.com/version/distro"
|
||||
)
|
||||
|
||||
func init() {
|
||||
osVersion = osVersionFreebsd
|
||||
osVersion = lazyOSVersion.Get
|
||||
distroName = distroNameFreeBSD
|
||||
distroVersion = distroVersionFreeBSD
|
||||
}
|
||||
|
||||
func osVersionFreebsd() string {
|
||||
un := unix.Utsname{}
|
||||
var (
|
||||
lazyVersionMeta = &lazyAtomicValue[versionMeta]{f: ptrTo(freebsdVersionMeta)}
|
||||
lazyOSVersion = &lazyAtomicValue[string]{f: ptrTo(osVersionFreeBSD)}
|
||||
)
|
||||
|
||||
func distroNameFreeBSD() string {
|
||||
return lazyVersionMeta.Get().DistroName
|
||||
}
|
||||
|
||||
func distroVersionFreeBSD() string {
|
||||
return lazyVersionMeta.Get().DistroVersion
|
||||
}
|
||||
|
||||
type versionMeta struct {
|
||||
DistroName string
|
||||
DistroVersion string
|
||||
DistroCodeName string
|
||||
}
|
||||
|
||||
func osVersionFreeBSD() string {
|
||||
var un unix.Utsname
|
||||
unix.Uname(&un)
|
||||
return unix.ByteSliceToString(un.Release[:])
|
||||
}
|
||||
|
||||
var attrBuf strings.Builder
|
||||
attrBuf.WriteString("; version=")
|
||||
attrBuf.WriteString(unix.ByteSliceToString(un.Release[:]))
|
||||
attr := attrBuf.String()
|
||||
|
||||
version := "FreeBSD"
|
||||
switch distro.Get() {
|
||||
func freebsdVersionMeta() (meta versionMeta) {
|
||||
d := distro.Get()
|
||||
meta.DistroName = string(d)
|
||||
switch d {
|
||||
case distro.Pfsense:
|
||||
b, _ := os.ReadFile("/etc/version")
|
||||
version = fmt.Sprintf("pfSense %s", b)
|
||||
meta.DistroVersion = string(bytes.TrimSpace(b))
|
||||
case distro.OPNsense:
|
||||
b, err := exec.Command("opnsense-version").Output()
|
||||
if err == nil {
|
||||
version = string(b)
|
||||
} else {
|
||||
version = "OPNsense"
|
||||
}
|
||||
b, _ := exec.Command("opnsense-version").Output()
|
||||
meta.DistroVersion = string(bytes.TrimSpace(b))
|
||||
case distro.TrueNAS:
|
||||
b, err := os.ReadFile("/etc/version")
|
||||
if err == nil {
|
||||
version = string(b)
|
||||
} else {
|
||||
version = "TrueNAS"
|
||||
}
|
||||
b, _ := os.ReadFile("/etc/version")
|
||||
meta.DistroVersion = string(bytes.TrimSpace(b))
|
||||
}
|
||||
// the /etc/version files end in a newline
|
||||
return fmt.Sprintf("%s%s", strings.TrimSuffix(version, "\n"), attr)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user