diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2021-02-08 08:48:50 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-02-08 21:15:18 +0100 |
| commit | bd8ccb52edfe3e1beee2fb9c3c5cc83a56d2800b (patch) | |
| tree | 87404ccd96de4869f8a5743231a91ddd85a14a80 | |
| parent | 00abbf4117f13c5e12f2ac79767b8779e02852aa (diff) | |
pkg/host: use unix.Utsname instead of syscall.Utsname
syscall.Utsname is hard to use portably, see:
https://github.com/google/syzkaller/pull/2418#issuecomment-774858512
Switch to unix.Utsname which does not have this problem.
| -rw-r--r-- | pkg/host/features_linux.go | 17 | ||||
| -rw-r--r-- | pkg/host/features_linux_test.go | 23 |
2 files changed, 29 insertions, 11 deletions
diff --git a/pkg/host/features_linux.go b/pkg/host/features_linux.go index ab8c2fc48..fc925c00c 100644 --- a/pkg/host/features_linux.go +++ b/pkg/host/features_linux.go @@ -14,6 +14,7 @@ import ( "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/prog" "github.com/google/syzkaller/sys/linux" + "golang.org/x/sys/unix" ) func init() { @@ -233,21 +234,15 @@ func checkWifiEmulation() string { } func requireKernel(x, y int) string { - info := new(syscall.Utsname) - if err := syscall.Uname(info); err != nil { + info := new(unix.Utsname) + if err := unix.Uname(info); err != nil { return fmt.Sprintf("uname failed: %v", err) } - var ver []byte - for _, b := range info.Release { - if b == 0 { - break - } - ver = append(ver, byte(b)) - } - if ok, bad := matchKernelVersion(string(ver), x, y); bad { + ver := string(info.Release[:]) + if ok, bad := matchKernelVersion(ver, x, y); bad { return fmt.Sprintf("failed to parse kernel version (%v)", ver) } else if !ok { - return fmt.Sprintf("kernel %v.%v required (have %s)", x, y, ver) + return fmt.Sprintf("kernel %v.%v required (have %v)", x, y, ver) } return "" } diff --git a/pkg/host/features_linux_test.go b/pkg/host/features_linux_test.go new file mode 100644 index 000000000..35d6197c1 --- /dev/null +++ b/pkg/host/features_linux_test.go @@ -0,0 +1,23 @@ +// Copyright 2021 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package host + +import ( + "strings" + "testing" +) + +func TestRequireKernel(t *testing.T) { + if what := requireKernel(2, 999); what != "" { + t.Fatalf("requireKernel(2, 999) failed: %v", what) + } + if what := requireKernel(3, 0); what != "" { + t.Fatalf("requireKernel(3, 0) failed: %v", what) + } + if what := requireKernel(99, 1); what == "" { + t.Fatalf("requireKernel(99, 1) succeeded") + } else if !strings.HasPrefix(what, "kernel 99.1 required") { + t.Fatalf("requireKernel(99, 1) failed: %v", what) + } +} |
