diff --git a/hostinfo/hostinfo.go b/hostinfo/hostinfo.go index 65fd676a82166..d01f6ffba94e8 100644 --- a/hostinfo/hostinfo.go +++ b/hostinfo/hostinfo.go @@ -52,7 +52,7 @@ func New() *tailcfg.Hostinfo { GoArchVar: lazyGoArchVar.Get(), GoVersion: runtime.Version(), Machine: condCall(unameMachine), - DeviceModel: deviceModel(), + DeviceModel: deviceModelCached(), PushDeviceToken: pushDeviceToken(), Cloud: string(cloudenv.Get()), NoLogsNoSupport: envknob.NoLogsNoSupport(), @@ -68,6 +68,7 @@ var ( distroVersion func() string distroCodeName func() string unameMachine func() string + deviceModel func() string ) func condCall[T any](fn func() T) T { @@ -115,6 +116,20 @@ func GetOSVersion() string { return "" } +func deviceModelCached() string { + if v, _ := deviceModelAtomic.Load().(string); v != "" { + return v + } + if deviceModel == nil { + return "" + } + v := deviceModel() + if v != "" { + deviceModelAtomic.Store(v) + } + return v +} + func appTypeCached() string { if v, ok := appType.Load().(string); ok { return v @@ -175,9 +190,6 @@ var ( // SetPushDeviceToken sets the device token for use in Hostinfo updates. func SetPushDeviceToken(token string) { pushDeviceTokenAtomic.Store(token) } -// SetDeviceModel sets the device model for use in Hostinfo updates. -func SetDeviceModel(model string) { deviceModelAtomic.Store(model) } - // SetOSVersion sets the OS version. func SetOSVersion(v string) { osVersionAtomic.Store(v) } @@ -192,11 +204,6 @@ func SetPackage(v string) { packagingType.Store(v) } // and "k8s-operator". func SetApp(v string) { appType.Store(v) } -func deviceModel() string { - s, _ := deviceModelAtomic.Load().(string) - return s -} - func pushDeviceToken() string { s, _ := pushDeviceTokenAtomic.Load().(string) return s diff --git a/hostinfo/hostinfo_linux.go b/hostinfo/hostinfo_linux.go index d52c084b8966a..d194fbb0da8b4 100644 --- a/hostinfo/hostinfo_linux.go +++ b/hostinfo/hostinfo_linux.go @@ -22,9 +22,7 @@ func init() { distroName = distroNameLinux distroVersion = distroVersionLinux distroCodeName = distroCodeNameLinux - if v := linuxDeviceModel(); v != "" { - SetDeviceModel(v) - } + deviceModel = deviceModelLinux } var ( @@ -50,7 +48,7 @@ func distroCodeNameLinux() string { return lazyVersionMeta.Get().DistroCodeName } -func linuxDeviceModel() string { +func deviceModelLinux() string { for _, path := range []string{ // First try the Synology-specific location. // Example: "DS916+-j"