From d1163f04801795d9c4f1fbf8c5611719cefe5b7e Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 27 Jan 2016 14:11:23 +0100 Subject: ipc: unify command line flag handling It was duplicated in 3 programs. --- ipc/ipc.go | 31 +++++++++++++++++++++++++++++++ ipc/ipc_test.go | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'ipc') 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 { -- cgit mrf-deployment