From efc2683657c742b741c0bb95fb993d7e1fb6843a Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 31 Jul 2018 18:36:30 +0200 Subject: pkg/csource: rafactor option checking Update #538 --- pkg/csource/common.go | 4 +--- pkg/csource/options.go | 52 ++++++++++++++++++++++++-------------------------- 2 files changed, 26 insertions(+), 30 deletions(-) (limited to 'pkg/csource') diff --git a/pkg/csource/common.go b/pkg/csource/common.go index 899d350e1..fa1c19f2e 100644 --- a/pkg/csource/common.go +++ b/pkg/csource/common.go @@ -16,9 +16,7 @@ import ( ) const ( - linux = "linux" - akaros = "akaros" - fuchsia = "fuchsia" + linux = "linux" sandboxNone = "none" sandboxSetuid = "setuid" diff --git a/pkg/csource/options.go b/pkg/csource/options.go index a312c5db7..061b20246 100644 --- a/pkg/csource/options.go +++ b/pkg/csource/options.go @@ -44,33 +44,6 @@ type Options struct { // For example, Collide without Threaded is not valid. // Invalid combinations must not be passed to Write. func (opts Options) Check(OS string) error { - switch OS { - case fuchsia, akaros: - if opts.Fault { - return fmt.Errorf("Fault is not supported on %v", OS) - } - if opts.EnableTun { - return fmt.Errorf("EnableTun is not supported on %v", OS) - } - if opts.EnableCgroups { - return fmt.Errorf("EnableCgroups is not supported on %v", OS) - } - if opts.EnableNetdev { - return fmt.Errorf("EnableNetdev is not supported on %v", OS) - } - if opts.ResetNet { - return fmt.Errorf("ResetNet is not supported on %v", OS) - } - if opts.Sandbox != "" && opts.Sandbox != sandboxNone { - return fmt.Errorf("Sandbox=%v is not supported on %v", opts.Sandbox, OS) - } - } - if OS != linux && (opts.Sandbox == sandboxNamespace || opts.Sandbox == sandboxSetuid) { - return fmt.Errorf("Sandbox=%v is not supported on %v", opts.Sandbox, OS) - } - if OS != linux && opts.Fault { - return fmt.Errorf("Fault is not supported on %v", OS) - } if !opts.Threaded && opts.Collide { // Collide requires threaded. return errors.New("Collide without Threaded") @@ -106,6 +79,31 @@ func (opts Options) Check(OS string) error { if !opts.Repeat && opts.RepeatTimes != 0 && opts.RepeatTimes != 1 { return errors.New("RepeatTimes without Repeat") } + return opts.checkLinuxOnly(OS) +} + +func (opts Options) checkLinuxOnly(OS string) error { + if OS == linux { + return nil + } + if opts.EnableTun { + return fmt.Errorf("EnableTun is not supported on %v", OS) + } + if opts.EnableCgroups { + return fmt.Errorf("EnableCgroups is not supported on %v", OS) + } + if opts.EnableNetdev { + return fmt.Errorf("EnableNetdev is not supported on %v", OS) + } + if opts.ResetNet { + return fmt.Errorf("ResetNet is not supported on %v", OS) + } + if opts.Sandbox == sandboxNamespace || opts.Sandbox == sandboxSetuid { + return fmt.Errorf("Sandbox=%v is not supported on %v", opts.Sandbox, OS) + } + if opts.Fault { + return fmt.Errorf("Fault is not supported on %v", OS) + } return nil } -- cgit mrf-deployment