diff --git a/cmd/prometheus/uname_linux.go b/cmd/prometheus/uname_linux.go index 865356816..4a4305663 100644 --- a/cmd/prometheus/uname_linux.go +++ b/cmd/prometheus/uname_linux.go @@ -25,6 +25,7 @@ func Uname() string { if err != nil { log.Fatal("Error!") } + str := "(" + charsToString(buf.Sysname[:]) str += " " + charsToString(buf.Release[:]) str += " " + charsToString(buf.Version[:]) diff --git a/cmd/prometheus/uname_linux_int8.go b/cmd/prometheus/uname_linux_int8.go index 40cfb5753..210e55c93 100644 --- a/cmd/prometheus/uname_linux_int8.go +++ b/cmd/prometheus/uname_linux_int8.go @@ -17,9 +17,12 @@ package main func charsToString(ca []int8) string { - s := make([]byte, len(ca)) - for i, c := range ca { - s[i] = byte(c) + s := make([]byte, 0, len(ca)) + for _, c := range ca { + if byte(c) == 0 { + break + } + s = append(s, byte(c)) } - return string(s[0:len(ca)]) + return string(s) } diff --git a/cmd/prometheus/uname_linux_uint8.go b/cmd/prometheus/uname_linux_uint8.go index da5794caa..e7282923e 100644 --- a/cmd/prometheus/uname_linux_uint8.go +++ b/cmd/prometheus/uname_linux_uint8.go @@ -17,9 +17,12 @@ package main func charsToString(ca []uint8) string { - s := make([]byte, len(ca)) - for i, c := range ca { - s[i] = byte(c) + s := make([]byte, 0, len(ca)) + for _, c := range ca { + if byte(c) == 0 { + break + } + s = append(s, byte(c)) } - return string(s[0:len(ca)]) + return string(s) }