mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 14:57:49 +00:00
control/controlclient: use "getprop net.hostname" for Android hostname
Updates #409
This commit is contained in:
parent
2b74236567
commit
afb9c6a6ab
@ -18,7 +18,9 @@
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -159,7 +161,13 @@ func NewDirect(opts Options) (*Direct, error) {
|
||||
}
|
||||
|
||||
func NewHostinfo() *tailcfg.Hostinfo {
|
||||
hostname, _ := os.Hostname()
|
||||
var hostname string
|
||||
if runtime.GOOS == "android" {
|
||||
hostname = androidHostname()
|
||||
}
|
||||
if hostname == "" {
|
||||
hostname, _ = os.Hostname()
|
||||
}
|
||||
return &tailcfg.Hostinfo{
|
||||
IPNVersion: version.LONG,
|
||||
Hostname: hostname,
|
||||
@ -167,6 +175,20 @@ func NewHostinfo() *tailcfg.Hostinfo {
|
||||
}
|
||||
}
|
||||
|
||||
var androidHostnameOnce struct {
|
||||
_ structs.Incomparable
|
||||
sync.Once
|
||||
v string
|
||||
}
|
||||
|
||||
func androidHostname() string {
|
||||
androidHostnameOnce.Do(func() {
|
||||
out, _ := exec.Command("getprop", "net.hostname").Output()
|
||||
androidHostnameOnce.v = strings.TrimSpace(string(out))
|
||||
})
|
||||
return androidHostnameOnce.v
|
||||
}
|
||||
|
||||
// SetHostinfo clones the provided Hostinfo and remembers it for the
|
||||
// next update. It reports whether the Hostinfo has changed.
|
||||
func (c *Direct) SetHostinfo(hi *tailcfg.Hostinfo) bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user