From e6e35dba937599d098fc034eff2686e5ddc409e9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 26 Oct 2020 10:51:06 +0100 Subject: sys/targets: add OS/Arch name consts We use strings to identify OS/Arch. These strings are duplicated throughout the code base massively. golangci-lint points to possiblity of typos and duplication. We already had to define these names in pkg/csource and disable checking for prog package. A future change triggers such warnings in another package. Add OS/Arch name consts to sys/targets so that they can be used to refer to OS/Arch. Use the consts everywhere. --- pkg/csource/options.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'pkg/csource/options.go') diff --git a/pkg/csource/options.go b/pkg/csource/options.go index ba74eb37c..7f2bc5109 100644 --- a/pkg/csource/options.go +++ b/pkg/csource/options.go @@ -12,6 +12,7 @@ import ( "strings" "github.com/google/syzkaller/pkg/mgrconfig" + "github.com/google/syzkaller/sys/targets" ) // Options control various aspects of source generation. @@ -113,10 +114,10 @@ func (opts Options) Check(OS string) error { } func (opts Options) checkLinuxOnly(OS string) error { - if OS == linux { + if OS == targets.Linux { return nil } - if opts.NetInjection && !(OS == openbsd || OS == freebsd || OS == netbsd) { + if opts.NetInjection && !(OS == targets.OpenBSD || OS == targets.FreeBSD || OS == targets.NetBSD) { return fmt.Errorf("option NetInjection is not supported on %v", OS) } if opts.NetDevices { @@ -150,7 +151,7 @@ func (opts Options) checkLinuxOnly(OS string) error { return fmt.Errorf("option Wifi is not supported on %v", OS) } if opts.Sandbox == sandboxNamespace || - (opts.Sandbox == sandboxSetuid && !(OS == openbsd || OS == freebsd || OS == netbsd)) || + (opts.Sandbox == sandboxSetuid && !(OS == targets.OpenBSD || OS == targets.FreeBSD || OS == targets.NetBSD)) || opts.Sandbox == sandboxAndroid { return fmt.Errorf("option Sandbox=%v is not supported on %v", opts.Sandbox, OS) } @@ -183,7 +184,7 @@ func DefaultOpts(cfg *mgrconfig.Config) Options { HandleSegv: true, Repro: true, } - if cfg.TargetOS != linux { + if cfg.TargetOS != targets.Linux { opts.NetInjection = false opts.NetDevices = false opts.NetReset = false -- cgit mrf-deployment