Skip to content

Commit

Permalink
Fix go routine problem with netns
Browse files Browse the repository at this point in the history
The exec command needs to be executed within the same go routine
  • Loading branch information
PouuleT committed Oct 13, 2016
1 parent d541db7 commit 3eb5418
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 3eb5418

Please sign in to comment.