Skip to content

Commit

Permalink
fix: properly register signal trap to cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Nov 6, 2020
1 parent adcb730 commit 05d31fb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions bin/vproxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ func startClientMode(addr string) {
var cmd *exec.Cmd
if len(args) > 1 {
cmd = runCommand(args[1:])

// trap signal for later cleanup
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
// catch ^c, cleanup
s := <-c
if s == nil {
return
}
fmt.Println("[*] caught signal:", s)
stopCommand(cmd)
os.Exit(0)
}()
}

var binding string
Expand All @@ -45,15 +59,6 @@ func startClientMode(addr string) {
log.Fatalf("error starting client: %s\n", err)
}

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
// catch ^c, cleanup
<-c
stopCommand(cmd)
os.Exit(0)
}()

defer res.Body.Close()
r := bufio.NewReader(res.Body)
for {
Expand Down

0 comments on commit 05d31fb

Please sign in to comment.