From 3a926348a4ef96e595b8f18c21d18ebdb7b45359 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 1 Jun 2022 15:03:00 +0200 Subject: [PATCH] hostinfo: use ByteSliceToString from golang.org/x/sys/unix Use unix.ByteSliceToString in osVersionFreebsd and osVersionLinux to convert the Utsname.Release []byte field to string. Signed-off-by: Tobias Klauser --- hostinfo/hostinfo_freebsd.go | 7 +------ hostinfo/hostinfo_linux.go | 8 ++------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/hostinfo/hostinfo_freebsd.go b/hostinfo/hostinfo_freebsd.go index f97fb762e..ffb7417c1 100644 --- a/hostinfo/hostinfo_freebsd.go +++ b/hostinfo/hostinfo_freebsd.go @@ -27,12 +27,7 @@ func osVersionFreebsd() string { var attrBuf strings.Builder attrBuf.WriteString("; version=") - for _, b := range un.Release { - if b == 0 { - break - } - attrBuf.WriteByte(byte(b)) - } + attrBuf.WriteString(unix.ByteSliceToString(un.Release[:])) attr := attrBuf.String() version := "FreeBSD" diff --git a/hostinfo/hostinfo_linux.go b/hostinfo/hostinfo_linux.go index a659490b9..9028cd696 100644 --- a/hostinfo/hostinfo_linux.go +++ b/hostinfo/hostinfo_linux.go @@ -14,6 +14,7 @@ import ( "os" "strings" + "golang.org/x/sys/unix" "tailscale.com/util/lineread" "tailscale.com/version/distro" ) @@ -72,12 +73,7 @@ func osVersionLinux() string { var attrBuf strings.Builder attrBuf.WriteString("; kernel=") - for _, b := range un.Release { - if b == 0 { - break - } - attrBuf.WriteByte(byte(b)) - } + attrBuf.WriteString(unix.ByteSliceToString(un.Release[:])) if inContainer() { attrBuf.WriteString("; container") }