Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/cmd/infra/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/router"
controllerfactory "github.com/openshift/origin/pkg/router/controller/factory"
"github.com/openshift/origin/pkg/util/proc"
"github.com/openshift/origin/pkg/version"
templateplugin "github.com/openshift/origin/plugins/router/template"
)
Expand Down Expand Up @@ -82,6 +83,8 @@ func start(cfg *clientcmd.Config, plugin router.Plugin) error {
return err
}

proc.StartReaper()

factory := controllerfactory.RouterControllerFactory{kubeClient, osClient}
controller := factory.Create(plugin)
controller.Run()
Expand Down
41 changes: 41 additions & 0 deletions pkg/util/proc/reaper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// +build linux

package proc

import (
"os"
"os/signal"
"syscall"

"github.com/golang/glog"
)

// StartReaper starts a goroutine to reap processes if called from a process
// that has pid 1.
func StartReaper() {
if os.Getpid() == 1 {
glog.V(4).Infof("Launching reaper")
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGCHLD)
for {
// Wait for a child to terminate
sig := <-sigs
glog.V(4).Infof("Signal received: %v", sig)
for {
// Reap processes
glog.V(4).Infof("Waiting to reap")
cpid, err := syscall.Wait4(-1, nil, 0, nil)

// Break out if there are no more processes to reap
if err == syscall.ECHILD {
glog.V(4).Infof("Received: %v", err)
break
}

glog.V(4).Infof("Reaped process with pid %d", cpid)
}
}
}()
}
}
8 changes: 8 additions & 0 deletions pkg/util/proc/reaper_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build !linux

package proc

// StartReaper has no effect on non-linux platforms.
// Support for other unices will be added.
func StartReaper() {
}