From 01622de2d0ec3b6cc18aef5bcbd5e76dd634116e Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 12 Sep 2020 17:12:12 +0200 Subject: 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. --- pkg/host/machine_info.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pkg/host/machine_info.go (limited to 'pkg/host/machine_info.go') 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 +} -- cgit mrf-deployment