mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
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 <tklauser@distanz.ch>
This commit is contained in:
parent
be330ac035
commit
7ef6f287cf
|
@ -13,11 +13,7 @@
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import "golang.org/x/sys/unix"
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Uname returns the uname of the host machine.
|
// Uname returns the uname of the host machine.
|
||||||
func Uname() string {
|
func Uname() string {
|
||||||
|
@ -27,11 +23,11 @@ func Uname() string {
|
||||||
panic("unix.Uname failed: " + err.Error())
|
panic("unix.Uname failed: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
str := "(" + string(buf.Sysname[:bytes.IndexByte(buf.Sysname[:], 0)])
|
str := "(" + unix.ByteSliceToString(buf.Sysname[:])
|
||||||
str += " " + string(buf.Release[:bytes.IndexByte(buf.Release[:], 0)])
|
str += " " + unix.ByteSliceToString(buf.Release[:])
|
||||||
str += " " + string(buf.Version[:bytes.IndexByte(buf.Version[:], 0)])
|
str += " " + unix.ByteSliceToString(buf.Version[:])
|
||||||
str += " " + string(buf.Machine[:bytes.IndexByte(buf.Machine[:], 0)])
|
str += " " + unix.ByteSliceToString(buf.Machine[:])
|
||||||
str += " " + string(buf.Nodename[:bytes.IndexByte(buf.Nodename[:], 0)])
|
str += " " + unix.ByteSliceToString(buf.Nodename[:])
|
||||||
str += " " + string(buf.Domainname[:bytes.IndexByte(buf.Domainname[:], 0)]) + ")"
|
str += " " + unix.ByteSliceToString(buf.Domainname[:]) + ")"
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue