Skip to content

Commit

Permalink
Avoid child processes
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Apr 9, 2017
1 parent 7c635a8 commit 1c6c427
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions controllers/nginx/pkg/cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ import (
)

func main() {
callback := func(pid int, wstatus syscall.WaitStatus) {
glog.V(2).Infof("removing child process pid %d, wstatus: %+v\n", pid, wstatus)
}

sig := make(chan os.Signal, 1024)
signal.Notify(sig, syscall.SIGCHLD)
go reapChildren(sig, callback)

// start a new nginx controller
ngx := newNGINXController()
// create a custom Ingress controller using NGINX as backend
Expand Down Expand Up @@ -58,3 +66,18 @@ func handleSigterm(ic *controller.GenericController) {
glog.Infof("Exiting with %v", exitCode)
os.Exit(exitCode)
}

func reapChildren(signal chan os.Signal, callback func(int, syscall.WaitStatus)) {
for {
<-signal
for {
var status syscall.WaitStatus
pid, _ := syscall.Wait4(-1, &status, 0, nil)
if pid <= 0 {
break
}
callback(pid, status)
break
}
}
}

0 comments on commit 1c6c427

Please sign in to comment.