From 3eb54186bb45307ef74d1d5a1c64ad3d256d087a Mon Sep 17 00:00:00 2001 From: Lucas BEE Date: Thu, 13 Oct 2016 16:16:59 +0000 Subject: [PATCH] Fix go routine problem with netns The exec command needs to be executed within the same go routine --- main.go | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/main.go b/main.go index 4cda500..2f9bc7d 100644 --- a/main.go +++ b/main.go @@ -226,28 +226,27 @@ func main() { signal.Notify(c, syscall.SIGINT) signal.Notify(c, syscall.SIGTERM) - // Launch the command in a go routine + // Wait for the process to end go func() { - err = execCmd(command) - if err != nil { - log.Warn("Error while running command : ", err) + for { + select { + // If we recieve a signal, we let it flow to the process + case signal := <-c: + log.Debugf("Got a %s", signal.String()) + // If the process is done, we exit properly + case <-done: + log.Debugf("Process exited properly, exiting") + return + } } - done <- struct{}{} }() - // Wait for the process to end -FOR_LOOP: - for { - select { - // If we recieve a signal, we let it flow to the process - case signal := <-c: - log.Debugf("Got a %s", signal.String()) - // If the process is done, we exit properly - case <-done: - log.Debugf("Process exited properly, exiting") - break FOR_LOOP - } + // Launch the command in a go routine + err = execCmd(command) + if err != nil { + log.Warn("Error while running command : ", err) } + done <- struct{}{} log.Debug("Go back to orignal namspace")