From 3fdd1a9249ddb8a6b5d85c61892977daf6d02460 Mon Sep 17 00:00:00 2001 From: sago35 Date: Fri, 5 Mar 2021 08:48:25 +0900 Subject: [PATCH] gdb: kill openocd if it does not exit --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 91b9c42a..e5b0c76e 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "path/filepath" "runtime" "strings" + "sync/atomic" "syscall" "time" @@ -464,8 +465,15 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro } defer func() { daemon.Process.Signal(os.Interrupt) - // Maybe we should send a .Kill() after x seconds? + var stopped uint32 + go func() { + time.Sleep(time.Millisecond * 100) + if atomic.LoadUint32(&stopped) == 0 { + daemon.Process.Kill() + } + }() daemon.Wait() + atomic.StoreUint32(&stopped, 1) }() }