Browse Source

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 <[email protected]>
Tobias Klauser 3 years ago
parent
commit
3a926348a4
2 changed files with 3 additions and 12 deletions
  1. 1 6
      hostinfo/hostinfo_freebsd.go
  2. 2 6
      hostinfo/hostinfo_linux.go

+ 1 - 6
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"

+ 2 - 6
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")
 	}