@@ -21,18 +21,19 @@ func Run() {
2121 if err != nil {
2222 log .Fatal ("failed to start ContainerPilot worker process:" , err )
2323 }
24- handleSignals (proc .Pid )
24+ passThroughSignals (proc .Pid )
25+ handleReaping (proc .Pid )
2526 proc .Wait ()
2627}
2728
28- // handleSignals listens for signals used to gracefully shutdown and
29+ // passThroughSignals listens for signals used to gracefully shutdown and
2930// passes them thru to the ContainerPilot worker process.
30- func handleSignals (pid int ) {
31- sig := make (chan os.Signal , 1 )
32- signal .Notify (sig , syscall .SIGTERM , syscall .SIGHUP , syscall .SIGINT , syscall . SIGCHLD , syscall .SIGUSR1 )
31+ func passThroughSignals (pid int ) {
32+ sigRecv := make (chan os.Signal , 1 )
33+ signal .Notify (sigRecv , syscall .SIGTERM , syscall .SIGHUP , syscall .SIGINT , syscall .SIGUSR1 )
3334 go func () {
34- for signal := range sig {
35- switch signal {
35+ for sig := range sigRecv {
36+ switch sig {
3637 case syscall .SIGINT :
3738 syscall .Kill (pid , syscall .SIGINT )
3839 case syscall .SIGTERM :
@@ -41,13 +42,24 @@ func handleSignals(pid int) {
4142 syscall .Kill (pid , syscall .SIGHUP )
4243 case syscall .SIGUSR1 :
4344 syscall .Kill (pid , syscall .SIGUSR1 )
44- case syscall .SIGCHLD :
45- go reap ()
4645 }
4746 }
4847 }()
4948}
5049
50+ // handleReaping listens for the SIGCHLD signal only and triggers
51+ // reaping of child processes
52+ func handleReaping (pid int ) {
53+ sigRecv := make (chan os.Signal , 1 )
54+ signal .Notify (sigRecv , syscall .SIGCHLD )
55+ go func () {
56+ for {
57+ <- sigRecv
58+ reap ()
59+ }
60+ }()
61+ }
62+
5163// reaps child processes that have been reparented to PID1
5264func reap () {
5365 for {
0 commit comments