diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-07-31 18:36:30 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-07-31 18:43:45 +0200 |
| commit | efc2683657c742b741c0bb95fb993d7e1fb6843a (patch) | |
| tree | b55025f3ac4c0433887ddb8d7e679910ffdb11de /pkg/csource | |
| parent | 46bad7854216a9ab0221d4e3a6144501b49537f5 (diff) | |
pkg/csource: rafactor option checking
Update #538
Diffstat (limited to 'pkg/csource')
| -rw-r--r-- | pkg/csource/common.go | 4 | ||||
| -rw-r--r-- | pkg/csource/options.go | 52 |
2 files changed, 26 insertions, 30 deletions
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 } |
