Skip to content

Commit

Permalink
repro: a little bit more graceful shutdown
Browse files Browse the repository at this point in the history
Bring down at least some VM instances.
Booting instances can still leak.
  • Loading branch information
dvyukov committed Aug 28, 2016
1 parent 76f68d6 commit 0113f7f
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions tools/syz-repro/repro.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"io/ioutil"
"log"
"os"
"os/signal"
"path/filepath"
"sort"
"syscall"
"time"

"github.com/google/syzkaller/config"
Expand All @@ -29,6 +31,7 @@ var (

instances chan VM
bootRequests chan bool
shutdown = make(chan struct{})
)

type VM struct {
Expand Down Expand Up @@ -93,14 +96,27 @@ func main() {
}()
}

go func() {
c := make(chan os.Signal, 2)
signal.Notify(c, syscall.SIGINT)
<-c
close(shutdown)
log.Printf("shutting down...")
<-c
log.Fatalf("terminating")
}()

repro(cfg, entries, crashStart)
exit()
}

func exit() {
for {
select {
case inst := <-instances:
inst.Close()
default:
return
os.Exit(0)
}
}
}
Expand Down Expand Up @@ -191,7 +207,12 @@ func returnInstance(inst VM, res bool) {

func testProg(cfg *config.Config, p *prog.Prog, multiplier int, threaded, collide bool) (res bool) {
log.Printf("booting VM")
inst := <-instances
var inst VM
select {
case inst = <-instances:
case <-shutdown:
exit()
}
defer func() {
returnInstance(inst, res)
}()
Expand Down Expand Up @@ -225,7 +246,12 @@ func testProg(cfg *config.Config, p *prog.Prog, multiplier int, threaded, collid

func testBin(cfg *config.Config, bin string) (res bool) {
log.Printf("booting VM")
inst := <-instances
var inst VM
select {
case inst = <-instances:
case <-shutdown:
exit()
}
defer func() {
returnInstance(inst, res)
}()
Expand Down Expand Up @@ -259,6 +285,9 @@ func testImpl(inst vm.Instance, command string, timeout time.Duration) (res bool
}
log.Printf("program did not crash")
return false
case <-shutdown:
inst.Close()
exit()
}
}
}

0 comments on commit 0113f7f

Please sign in to comment.