aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-12-16 14:21:05 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-12-25 10:12:41 +0100
commit55adcb8ca0ca0b7185e917ece137fae218365c89 (patch)
tree58b8661c65496f0a3fa2e7824bf1ebbc97c6d275 /sys
parent257f4cb9050d29a38a992b814bd6e79e6f1bca99 (diff)
all: use tool.Failf instead of local functions
Diffstat (limited to 'sys')
-rw-r--r--sys/fuchsia/fidlgen/main.go22
-rw-r--r--sys/syz-extract/extract.go17
-rw-r--r--sys/syz-sysgen/sysgen.go13
3 files changed, 20 insertions, 32 deletions
diff --git a/sys/fuchsia/fidlgen/main.go b/sys/fuchsia/fidlgen/main.go
index b4942a08d..937ef62d1 100644
--- a/sys/fuchsia/fidlgen/main.go
+++ b/sys/fuchsia/fidlgen/main.go
@@ -13,6 +13,7 @@ import (
"github.com/google/syzkaller/pkg/ast"
"github.com/google/syzkaller/pkg/compiler"
"github.com/google/syzkaller/pkg/osutil"
+ "github.com/google/syzkaller/pkg/tool"
"github.com/google/syzkaller/sys/fuchsia/layout"
"github.com/google/syzkaller/sys/targets"
)
@@ -21,13 +22,13 @@ func main() {
targetArch := os.Getenv("TARGETARCH")
target := targets.Get(targets.Fuchsia, targetArch)
if target == nil {
- failf("unknown TARGETARCH %s", targetArch)
+ tool.Failf("unknown TARGETARCH %s", targetArch)
}
arch := target.KernelHeaderArch
sourceDir := os.Getenv("SOURCEDIR")
if !osutil.IsExist(sourceDir) {
- failf("cannot find SOURCEDIR %s", sourceDir)
+ tool.Failf("cannot find SOURCEDIR %s", sourceDir)
}
fidlgenPath := filepath.Join(
@@ -38,7 +39,7 @@ func main() {
"fidlgen_syzkaller",
)
if !osutil.IsExist(fidlgenPath) {
- failf("cannot find fidlgen %s", fidlgenPath)
+ tool.Failf("cannot find fidlgen %s", fidlgenPath)
}
var newFiles []string
@@ -62,14 +63,14 @@ func main() {
errorMsg = msg
})
if desc == nil {
- failf("parsing failed at %v: %v", errorPos, errorMsg)
+ tool.Failf("parsing failed at %v: %v", errorPos, errorMsg)
}
unused := make(map[ast.Node]bool)
nodes, err := compiler.CollectUnused(desc, target, nil)
if err != nil {
- failf("collect unused nodes failed: %v", err)
+ tool.Failf("collect unused nodes failed: %v", err)
}
for _, n := range nodes {
@@ -88,14 +89,14 @@ func main() {
}))
if err := osutil.WriteFile(file, desc); err != nil {
- failf("%v", err)
+ tool.Fail(err)
}
}
}
func fidlgen(fidlgenPath, jsonPath, txtPathBase string) string {
if !osutil.IsExist(jsonPath) {
- failf("cannot find %s", jsonPath)
+ tool.Failf("cannot find %s", jsonPath)
}
out, err := osutil.RunCmd(time.Minute, "",
@@ -108,13 +109,8 @@ func fidlgen(fidlgenPath, jsonPath, txtPathBase string) string {
}
if err != nil {
- failf("fidlgen failed: %v", err)
+ tool.Failf("fidlgen failed: %v", err)
}
return fmt.Sprintf("%s.syz.txt", txtPathBase)
}
-
-func failf(msg string, args ...interface{}) {
- fmt.Fprintf(os.Stderr, msg+"\n", args...)
- os.Exit(1)
-}
diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go
index 477877d3c..d8ae1eeda 100644
--- a/sys/syz-extract/extract.go
+++ b/sys/syz-extract/extract.go
@@ -17,6 +17,7 @@ import (
"github.com/google/syzkaller/pkg/ast"
"github.com/google/syzkaller/pkg/compiler"
"github.com/google/syzkaller/pkg/osutil"
+ "github.com/google/syzkaller/pkg/tool"
"github.com/google/syzkaller/sys/targets"
)
@@ -69,30 +70,26 @@ var extractors = map[string]Extractor{
}
func main() {
- failf := func(msg string, args ...interface{}) {
- fmt.Fprintf(os.Stderr, msg+"\n", args...)
- os.Exit(1)
- }
flag.Parse()
if *flagBuild && *flagBuildDir != "" {
- failf("-build and -builddir is an invalid combination")
+ tool.Failf("-build and -builddir is an invalid combination")
}
OS, archArray, files, err := archFileList(*flagOS, *flagArch, flag.Args())
if err != nil {
- failf("%v", err)
+ tool.Fail(err)
}
extractor := extractors[OS]
if extractor == nil {
- failf("unknown os: %v", OS)
+ tool.Failf("unknown os: %v", OS)
}
arches, err := createArches(OS, archArray, files)
if err != nil {
- failf("%v", err)
+ tool.Fail(err)
}
if err := extractor.prepare(*flagSourceDir, *flagBuild, arches); err != nil {
- failf("%v", err)
+ tool.Fail(err)
}
jobC := make(chan interface{}, len(archArray)*len(files))
@@ -135,7 +132,7 @@ func main() {
continue
}
if err := osutil.WriteFile(outname, data); err != nil {
- failf("failed to write output file: %v", err)
+ tool.Failf("failed to write output file: %v", err)
}
}
diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go
index b62e1dff2..a17186731 100644
--- a/sys/syz-sysgen/sysgen.go
+++ b/sys/syz-sysgen/sysgen.go
@@ -173,7 +173,7 @@ func main() {
for what, count := range unsupported {
if count == len(jobs) {
- failf("%v is unsupported on all arches (typo?)", what)
+ tool.Failf("%v is unsupported on all arches (typo?)", what)
}
}
}
@@ -305,12 +305,12 @@ func writeExecutorSyscalls(data *ExecutorData) {
})
buf := new(bytes.Buffer)
if err := defsTempl.Execute(buf, data); err != nil {
- failf("failed to execute defs template: %v", err)
+ tool.Failf("failed to execute defs template: %v", err)
}
writeFile(filepath.Join(*outDir, "executor", "defs.h"), buf.Bytes())
buf.Reset()
if err := syscallsTempl.Execute(buf, data); err != nil {
- failf("failed to execute syscalls template: %v", err)
+ tool.Failf("failed to execute syscalls template: %v", err)
}
writeFile(filepath.Join(*outDir, "executor", "syscalls.h"), buf.Bytes())
}
@@ -325,17 +325,12 @@ func writeSource(file string, data []byte) {
func writeFile(file string, data []byte) {
outf, err := os.Create(file)
if err != nil {
- failf("failed to create output file: %v", err)
+ tool.Failf("failed to create output file: %v", err)
}
defer outf.Close()
outf.Write(data)
}
-func failf(msg string, args ...interface{}) {
- fmt.Fprintf(os.Stderr, msg+"\n", args...)
- os.Exit(1)
-}
-
var defsTempl = template.Must(template.New("").Parse(`// AUTOGENERATED FILE
struct call_attrs_t { {{range $attr := $.CallAttrs}}