diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-09-12 17:12:12 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-09-12 17:38:54 +0200 |
| commit | 01622de2d0ec3b6cc18aef5bcbd5e76dd634116e (patch) | |
| tree | 3bac8083af4a8cd50b641f68deebcc1851bfdad3 /pkg/host/machine_info.go | |
| parent | 7aa6bd6859a419bfb445a3621a14124fd7cecced (diff) | |
pkg/host: move machine info functionality from syz-fuzzer
It's better to keep functionality in packages rather than in main.
It makes it reusable and better organized.
Move machine info functionality to pkg/host and do some cosmetic refactoring.
Diffstat (limited to 'pkg/host/machine_info.go')
| -rw-r--r-- | pkg/host/machine_info.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/host/machine_info.go b/pkg/host/machine_info.go new file mode 100644 index 000000000..7a7cd2612 --- /dev/null +++ b/pkg/host/machine_info.go @@ -0,0 +1,34 @@ +// Copyright 2020 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 ( + "bytes" + "fmt" + "os" + "strings" +) + +func CollectMachineInfo() ([]byte, error) { + buf := new(bytes.Buffer) + for _, pair := range machineInfoFuncs { + fmt.Fprintf(buf, "[%s]\n", pair.name) + err := pair.fn(buf) + if err != nil { + if !os.IsNotExist(err) { + return nil, err + } + fmt.Fprintf(buf, "%v\n", err) + } + fmt.Fprintf(buf, "%v\n\n", strings.Repeat("-", 80)) + } + return buf.Bytes(), nil +} + +var machineInfoFuncs []machineInfoFunc + +type machineInfoFunc struct { + name string + fn func(*bytes.Buffer) error +} |
