From 7ef6f287cfc6fbe883238e4763570f43d922dcf2 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sat, 30 Jul 2022 19:35:03 +0200 Subject: [PATCH] util/runtime: use ByteSliceToString from golang.org/x/sys/unix in Uname (#11070) Use unix.ByteSliceToString to convert Utsname []byte fields to strings. Signed-off-by: Tobias Klauser --- util/runtime/uname_linux.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/util/runtime/uname_linux.go b/util/runtime/uname_linux.go index cf81b13ec..ce3bc42a2 100644 --- a/util/runtime/uname_linux.go +++ b/util/runtime/uname_linux.go @@ -13,11 +13,7 @@ package runtime -import ( - "bytes" - - "golang.org/x/sys/unix" -) +import "golang.org/x/sys/unix" // Uname returns the uname of the host machine. func Uname() string { @@ -27,11 +23,11 @@ func Uname() string { panic("unix.Uname failed: " + err.Error()) } - str := "(" + string(buf.Sysname[:bytes.IndexByte(buf.Sysname[:], 0)]) - str += " " + string(buf.Release[:bytes.IndexByte(buf.Release[:], 0)]) - str += " " + string(buf.Version[:bytes.IndexByte(buf.Version[:], 0)]) - str += " " + string(buf.Machine[:bytes.IndexByte(buf.Machine[:], 0)]) - str += " " + string(buf.Nodename[:bytes.IndexByte(buf.Nodename[:], 0)]) - str += " " + string(buf.Domainname[:bytes.IndexByte(buf.Domainname[:], 0)]) + ")" + str := "(" + unix.ByteSliceToString(buf.Sysname[:]) + str += " " + unix.ByteSliceToString(buf.Release[:]) + str += " " + unix.ByteSliceToString(buf.Version[:]) + str += " " + unix.ByteSliceToString(buf.Machine[:]) + str += " " + unix.ByteSliceToString(buf.Nodename[:]) + str += " " + unix.ByteSliceToString(buf.Domainname[:]) + ")" return str }