@ -17,11 +17,14 @@ import (
"go4.org/mem"
"go4.org/mem"
"tailscale.com/tailcfg"
"tailscale.com/tailcfg"
"tailscale.com/types/opt"
"tailscale.com/util/dnsname"
"tailscale.com/util/dnsname"
"tailscale.com/util/lineread"
"tailscale.com/util/lineread"
"tailscale.com/version"
"tailscale.com/version"
)
)
var started = time . Now ( )
// New returns a partially populated Hostinfo for the current host.
// New returns a partially populated Hostinfo for the current host.
func New ( ) * tailcfg . Hostinfo {
func New ( ) * tailcfg . Hostinfo {
hostname , _ := os . Hostname ( )
hostname , _ := os . Hostname ( )
@ -31,6 +34,7 @@ func New() *tailcfg.Hostinfo {
Hostname : hostname ,
Hostname : hostname ,
OS : version . OS ( ) ,
OS : version . OS ( ) ,
OSVersion : GetOSVersion ( ) ,
OSVersion : GetOSVersion ( ) ,
Desktop : desktop ( ) ,
Package : packageTypeCached ( ) ,
Package : packageTypeCached ( ) ,
GoArch : runtime . GOARCH ,
GoArch : runtime . GOARCH ,
DeviceModel : deviceModel ( ) ,
DeviceModel : deviceModel ( ) ,
@ -97,6 +101,7 @@ func GetEnvType() EnvType {
var (
var (
deviceModelAtomic atomic . Value // of string
deviceModelAtomic atomic . Value // of string
osVersionAtomic atomic . Value // of string
osVersionAtomic atomic . Value // of string
desktopAtomic atomic . Value // of opt.Bool
packagingType atomic . Value // of string
packagingType atomic . Value // of string
)
)
@ -117,6 +122,31 @@ func deviceModel() string {
return s
return s
}
}
func desktop ( ) ( ret opt . Bool ) {
if runtime . GOOS != "linux" {
return opt . Bool ( "" )
}
if v := desktopAtomic . Load ( ) ; v != nil {
v , _ := v . ( opt . Bool )
return v
}
seenDesktop := false
lineread . File ( "/proc/net/unix" , func ( line [ ] byte ) error {
seenDesktop = seenDesktop || mem . Contains ( mem . B ( line ) , mem . S ( " @/tmp/dbus-" ) )
seenDesktop = seenDesktop || mem . Contains ( mem . B ( line ) , mem . S ( ".X11-unix" ) )
seenDesktop = seenDesktop || mem . Contains ( mem . B ( line ) , mem . S ( "/wayland-1" ) )
return nil
} )
ret . Set ( seenDesktop )
// Only cache after a minute - compositors might not have started yet.
if time . Since ( started ) > time . Minute {
desktopAtomic . Store ( ret )
}
return ret
}
func getEnvType ( ) EnvType {
func getEnvType ( ) EnvType {
if inKnative ( ) {
if inKnative ( ) {
return KNative
return KNative