Simplify Utsname string conversion

Use Utsname from golang.org/x/sys/unix which contains byte array
instead of int8/uint8 array members. This allows to simplify the string
conversions of these members and the marshal.FromUtsname functions are
no longer needed.
This commit is contained in:
Tobias Klauser
2017-11-01 09:54:58 +01:00
parent ac6a629aa2
commit 89f3ce2e64
6 changed files with 18 additions and 59 deletions

View File

@@ -2,10 +2,11 @@ package host_test
import (
"fmt"
"syscall"
"testing"
"github.com/weaveworks/scope/probe/host"
"golang.org/x/sys/unix"
)
func TestUname(t *testing.T) {
@@ -16,9 +17,9 @@ func TestUname(t *testing.T) {
release = "rls"
version = "ver"
)
host.Uname = func(uts *syscall.Utsname) error {
uts.Release = string2c(release)
uts.Version = string2c(version)
host.Uname = func(uts *unix.Utsname) error {
copy(uts.Release[:], []byte(release))
copy(uts.Version[:], []byte(version))
return nil
}
@@ -31,11 +32,3 @@ func TestUname(t *testing.T) {
t.Errorf("want %q, have %q", want, have)
}
}
func string2c(s string) [65]int8 {
var result [65]int8
for i, c := range s {
result[i] = int8(c)
}
return result
}