hostinfo: retrieve OS version for Macs running the OSS client
Updates #18520 Change-Id: If86a1f702c704b003002aa7e2f5a6b1418b469cc Signed-off-by: Alex Chan <alexc@tailscale.com>
This commit is contained in:
@@ -8,14 +8,31 @@ package hostinfo
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
"tailscale.com/types/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
osVersion = lazyOSVersion.Get
|
||||||
packageType = packageTypeDarwin
|
packageType = packageTypeDarwin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
lazyOSVersion = &lazyAtomicValue[string]{f: ptr.To(osVersionDarwin)}
|
||||||
|
)
|
||||||
|
|
||||||
func packageTypeDarwin() string {
|
func packageTypeDarwin() string {
|
||||||
// Using tailscaled or IPNExtension?
|
// Using tailscaled or IPNExtension?
|
||||||
exe, _ := os.Executable()
|
exe, _ := os.Executable()
|
||||||
return filepath.Base(exe)
|
return filepath.Base(exe)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the marketing version (e.g., "15.0.1" or "26.0.0")
|
||||||
|
func osVersionDarwin() string {
|
||||||
|
version, err := unix.Sysctl("kern.osproductversion")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user