Skip to content

Commit dfc200b

Browse files
authored
Merge pull request #13 from PouuleT/dev/fixGoRoutine
Fix go routine problem with netns
2 parents d541db7 + 3eb5418 commit dfc200b

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

main.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,28 +226,27 @@ func main() {
226226
signal.Notify(c, syscall.SIGINT)
227227
signal.Notify(c, syscall.SIGTERM)
228228

229-
// Launch the command in a go routine
229+
// Wait for the process to end
230230
go func() {
231-
err = execCmd(command)
232-
if err != nil {
233-
log.Warn("Error while running command : ", err)
231+
for {
232+
select {
233+
// If we recieve a signal, we let it flow to the process
234+
case signal := <-c:
235+
log.Debugf("Got a %s", signal.String())
236+
// If the process is done, we exit properly
237+
case <-done:
238+
log.Debugf("Process exited properly, exiting")
239+
return
240+
}
234241
}
235-
done <- struct{}{}
236242
}()
237243

238-
// Wait for the process to end
239-
FOR_LOOP:
240-
for {
241-
select {
242-
// If we recieve a signal, we let it flow to the process
243-
case signal := <-c:
244-
log.Debugf("Got a %s", signal.String())
245-
// If the process is done, we exit properly
246-
case <-done:
247-
log.Debugf("Process exited properly, exiting")
248-
break FOR_LOOP
249-
}
244+
// Launch the command in a go routine
245+
err = execCmd(command)
246+
if err != nil {
247+
log.Warn("Error while running command : ", err)
250248
}
249+
done <- struct{}{}
251250

252251
log.Debug("Go back to orignal namspace")
253252

0 commit comments

Comments
 (0)