diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-01-27 14:11:23 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-01-27 14:22:48 +0100 |
| commit | d1163f04801795d9c4f1fbf8c5611719cefe5b7e (patch) | |
| tree | bac068949e1408cd26d0d16be8bb2c56f3d5362c /ipc | |
| parent | 9aec072a77b50a40e074d029573b65d4606ea1e1 (diff) | |
ipc: unify command line flag handling
It was duplicated in 3 programs.
Diffstat (limited to 'ipc')
| -rw-r--r-- | ipc/ipc.go | 31 | ||||
| -rw-r--r-- | ipc/ipc_test.go | 2 |
2 files changed, 32 insertions, 1 deletions
diff --git a/ipc/ipc.go b/ipc/ipc.go index eedf166df..b7c647478 100644 --- a/ipc/ipc.go +++ b/ipc/ipc.go @@ -6,6 +6,7 @@ package ipc import ( "bytes" "encoding/binary" + "flag" "fmt" "io/ioutil" "os" @@ -44,6 +45,36 @@ const ( FlagDropPrivs // impersonate nobody user ) +var ( + flagThreaded = flag.Bool("threaded", true, "use threaded mode in executor") + flagCollide = flag.Bool("collide", true, "collide syscalls to provoke data races") + flagCover = flag.Bool("cover", true, "collect coverage") + flagNobody = flag.Bool("nobody", true, "impersonate into nobody") + flagDebug = flag.Bool("debug", false, "debug output from executor") + flagTimeout = flag.Duration("timeout", 10*time.Second, "execution timeout") +) + +func DefaultFlags() (uint64, time.Duration) { + var flags uint64 + if *flagThreaded { + flags |= FlagThreaded + } + if *flagCollide { + flags |= FlagCollide + } + if *flagCover { + flags |= FlagCover + flags |= FlagDedupCover + } + if *flagNobody { + flags |= FlagDropPrivs + } + if *flagDebug { + flags |= FlagDebug + } + return flags, *flagTimeout +} + func MakeEnv(bin string, timeout time.Duration, flags uint64) (*Env, error) { // IPC timeout must be larger then executor timeout. // Otherwise IPC will kill parent executor but leave child executor alive. diff --git a/ipc/ipc_test.go b/ipc/ipc_test.go index af1fa6849..0628923e7 100644 --- a/ipc/ipc_test.go +++ b/ipc/ipc_test.go @@ -79,7 +79,7 @@ func TestExecute(t *testing.T) { defer os.Remove(bin) rs, iters := initTest(t) - flags := []uint64{0, FlagThreaded, FlagThreaded | FlagCollide} + flags := []uint64{0, FlagThreaded, FlagThreaded | FlagCollide, FlagDropPrivs, FlagDropPrivs | FlagThreaded} for _, flag := range flags { env, err := MakeEnv(bin, timeout, flag) if err != nil { |
