Created
February 4, 2017 07:05
-
-
Save fuzzy/a558eb3ea1658321875ccae72358f024 to your computer and use it in GitHub Desktop.
patch to github.com/zstyblik/go-facter/lib/host/host.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- host.orig.go 2017-02-03 23:03:06.070727000 -0800 | |
+++ host.go 2017-02-03 23:03:22.349835000 -0800 | |
@@ -53,6 +53,19 @@ | |
return strings.TrimRight(string(b), "\x00") | |
} | |
+// uint8ToString converts [65]uint8 in syscall.Utsname to string | |
+func uint8ToString(bs [65]uint8) string { | |
+ b := make([]byte, len(bs)) | |
+ for i, v := range bs { | |
+ if v < 0 { | |
+ b[i] = byte(256 + uint(v)) | |
+ } else { | |
+ b[i] = byte(v) | |
+ } | |
+ } | |
+ return strings.TrimRight(string(b), "\x00") | |
+} | |
+ | |
// GetHostFacts gathers facts related to Host | |
func GetHostFacts(f Facter) error { | |
hostInfo, err := h.Info() | |
@@ -105,14 +118,14 @@ | |
var uname syscall.Utsname | |
err = syscall.Uname(&uname) | |
if err == nil { | |
- kernelRelease := int8ToString(uname.Release) | |
+ kernelRelease := uint8ToString(uname.Release) | |
kernelVersion := strings.Split(kernelRelease, "-")[0] | |
kvSplitted := strings.Split(kernelVersion, ".") | |
f.Add("kernelrelease", kernelRelease) | |
f.Add("kernelversion", kernelVersion) | |
f.Add("kernelmajversion", strings.Join(kvSplitted[0:2], ".")) | |
- hardwareModel := int8ToString(uname.Machine) | |
+ hardwareModel := uint8ToString(uname.Machine) | |
f.Add("hardwaremodel", hardwareModel) | |
f.Add("architecture", guessArch(hardwareModel)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment