Skip to content

Commit

Permalink
move reaper from origin to here as it was deleted in source repository
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed Oct 19, 2020
1 parent af0172e commit 80f049b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -13,13 +13,13 @@ import (
"strconv"
"strings"

"github.com/openshift/origin/pkg/util/proc"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/klog/v2"

_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/openshift/openshift-state-metrics/pkg/proc"
"github.com/openshift/openshift-state-metrics/pkg/version"
kcollectors "k8s.io/kube-state-metrics/pkg/collector"
koptions "k8s.io/kube-state-metrics/pkg/options"
Expand Down
37 changes: 37 additions & 0 deletions pkg/proc/reaper.go
@@ -0,0 +1,37 @@
// +build linux

package proc

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

"k8s.io/klog/v2"
)

// StartReaper starts a goroutine to reap processes if called from a process
// that has pid 1.
func StartReaper() {
if os.Getpid() == 1 {
klog.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
klog.V(4).Infof("Signal received: %v", sig)
for {
// Reap processes
cpid, _ := syscall.Wait4(-1, nil, syscall.WNOHANG, nil)
if cpid < 1 {
break
}

klog.V(4).Infof("Reaped process with pid %d", cpid)
}
}
}()
}
}
8 changes: 8 additions & 0 deletions pkg/proc/reaper_unsupported.go
@@ -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() {
}

0 comments on commit 80f049b

Please sign in to comment.