From deafc3a0bfc888d1c3cf0c5865483a02b03acb6d Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Thu, 11 Oct 2012 08:00:42 -0700 Subject: [PATCH] handle ctrl-c --- examples/goroutines/goroutines.go | 8 ++++---- tools/build-loop | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/goroutines/goroutines.go b/examples/goroutines/goroutines.go index 98cd466..f3539e8 100644 --- a/examples/goroutines/goroutines.go +++ b/examples/goroutines/goroutines.go @@ -27,10 +27,10 @@ func main() { fmt.Println("going") }() - // Since our two goroutines are running asynchrously - // in separate goroutines now, execution immediatly - // falls through to here. This `Scanln` code requires - // that we press a key before the program exits. + // Our two goroutines are running asynchrously in + // separate goroutines now, so execution falls through + // to here. This `Scanln` code requires we press a key + // before the program exits. var input string fmt.Scanln(&input) fmt.Println("done") diff --git a/tools/build-loop b/tools/build-loop index 0d69f7f..5384701 100755 --- a/tools/build-loop +++ b/tools/build-loop @@ -1,12 +1,21 @@ #!/bin/bash +TRAPPING=0 +trap "{ echo finishing; TRAPPING=1; }" SIGINT + while : do tools/build - if [ "$?" == "0" ]; then + RET=$? + if [ $RET -eq 0 ]; then echo "success" else - echo "error" + echo "error: $RET" + fi + if [ $TRAPPING -eq 0 ]; then + sleep 1 + else + echo "done" + exit 0 fi - sleep 1 done