mirror of
https://github.com/reactos/syzkaller.git
synced 2024-10-07 17:13:26 +00:00
execprog: properly cleanup on ctrl+C
This commit is contained in:
parent
87d7cc4d27
commit
96949534ae
@ -13,7 +13,10 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/syzkaller/cover"
|
"github.com/google/syzkaller/cover"
|
||||||
@ -22,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
flagExecutor = flag.String("executor", "", "path to executor binary")
|
flagExecutor = flag.String("executor", "./syz-executor", "path to executor binary")
|
||||||
flagCoverFile = flag.String("coverfile", "", "write coverage to the file")
|
flagCoverFile = flag.String("coverfile", "", "write coverage to the file")
|
||||||
flagRepeat = flag.Int("repeat", 1, "repeat execution that many times (0 for infinite loop)")
|
flagRepeat = flag.Int("repeat", 1, "repeat execution that many times (0 for infinite loop)")
|
||||||
flagProcs = flag.Int("procs", 1, "number of parallel processes to execute programs")
|
flagProcs = flag.Int("procs", 1, "number of parallel processes to execute programs")
|
||||||
@ -63,12 +66,15 @@ func main() {
|
|||||||
var posMu sync.Mutex
|
var posMu sync.Mutex
|
||||||
var pos int
|
var pos int
|
||||||
var lastPrint time.Time
|
var lastPrint time.Time
|
||||||
|
var shutdown uint32
|
||||||
for p := 0; p < *flagProcs; p++ {
|
for p := 0; p < *flagProcs; p++ {
|
||||||
go func() {
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
env, err := ipc.MakeEnv(*flagExecutor, timeout, flags)
|
env, err := ipc.MakeEnv(*flagExecutor, timeout, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to create ipc env: %v", err)
|
log.Fatalf("failed to create ipc env: %v", err)
|
||||||
}
|
}
|
||||||
|
defer env.Close()
|
||||||
for {
|
for {
|
||||||
posMu.Lock()
|
posMu.Lock()
|
||||||
idx := pos
|
idx := pos
|
||||||
@ -79,12 +85,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
posMu.Unlock()
|
posMu.Unlock()
|
||||||
if *flagRepeat > 0 && idx >= len(progs)**flagRepeat {
|
if *flagRepeat > 0 && idx >= len(progs)**flagRepeat {
|
||||||
env.Close()
|
|
||||||
wg.Done()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p := progs[idx%len(progs)]
|
p := progs[idx%len(progs)]
|
||||||
output, cov, _, failed, hanged, err := env.Exec(p)
|
output, cov, _, failed, hanged, err := env.Exec(p)
|
||||||
|
if atomic.LoadUint32(&shutdown) != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
if failed {
|
if failed {
|
||||||
fmt.Printf("BUG: executor-detected bug:\n%s", output)
|
fmt.Printf("BUG: executor-detected bug:\n%s", output)
|
||||||
}
|
}
|
||||||
@ -114,5 +121,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
c := make(chan os.Signal, 2)
|
||||||
|
signal.Notify(c, syscall.SIGINT)
|
||||||
|
<-c
|
||||||
|
log.Printf("shutting down...")
|
||||||
|
atomic.StoreUint32(&shutdown, 1)
|
||||||
|
<-c
|
||||||
|
log.Fatalf("terminating")
|
||||||
|
}()
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user