fix: was reaping too fast?
This commit is contained in:
parent
ededf9aeb5
commit
ab9a10fbe3
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"novit.nc/direktil/pkg/log"
|
||||
@ -14,26 +15,25 @@ func handleChildren() {
|
||||
initLog.Taintf(log.Error, "reaper: failed to set myself a child sub-reaper: %v", err)
|
||||
}
|
||||
|
||||
sigchld := make(chan os.Signal, 10)
|
||||
signal.Notify(sigchld, unix.SIGCHLD)
|
||||
sigchld := make(chan os.Signal, 2048)
|
||||
signal.Notify(sigchld, syscall.SIGCHLD)
|
||||
|
||||
for range sigchld {
|
||||
// reap children
|
||||
var (
|
||||
ws unix.WaitStatus
|
||||
rus unix.Rusage
|
||||
)
|
||||
for {
|
||||
pid, err := unix.Wait4(-1, &ws, unix.WNOHANG, &rus)
|
||||
if err != nil {
|
||||
if err == unix.ECHILD {
|
||||
break
|
||||
}
|
||||
initLog.Taintf(log.Warning, "reaper: wait4 failed: %v", err)
|
||||
}
|
||||
if pid <= 0 {
|
||||
reapChildren()
|
||||
}
|
||||
}
|
||||
|
||||
func reapChildren() {
|
||||
for {
|
||||
pid, err := syscall.Wait4(-1, nil, syscall.WNOHANG, nil)
|
||||
if err != nil {
|
||||
if err == unix.ECHILD {
|
||||
break
|
||||
}
|
||||
initLog.Taintf(log.Warning, "reaper: wait4 failed: %v", err)
|
||||
}
|
||||
if pid <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user