Merge pull request #272 from runcom/remove-reaper

server: remove reaper, let runc take care of reaping
This commit is contained in:
Pengfei Ni 2016-12-14 22:38:03 +08:00 committed by GitHub
commit 7b0c76219c
3 changed files with 2 additions and 53 deletions

View file

@ -17,8 +17,8 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/cri-o/utils"
"github.com/containernetworking/cni/pkg/ns"
"github.com/kubernetes-incubator/cri-o/utils"
"golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/fields"
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
@ -275,6 +275,7 @@ func (r *Runtime) StopContainer(c *Container) error {
if err != nil && err != syscall.ESRCH {
return fmt.Errorf("failed to kill process: %v", err)
}
break
}
// Check if the process is still around
err := unix.Kill(c.state.Pid, 0)

View file

@ -15,7 +15,6 @@ import (
"github.com/kubernetes-incubator/cri-o/oci"
"github.com/kubernetes-incubator/cri-o/server/apparmor"
"github.com/kubernetes-incubator/cri-o/server/seccomp"
"github.com/kubernetes-incubator/cri-o/utils"
"github.com/opencontainers/runc/libcontainer/label"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/rajatchopra/ocicni"
@ -297,14 +296,6 @@ func seccompEnabled() bool {
// New creates a new Server with options provided
func New(config *Config) (*Server, error) {
// TODO: This will go away later when we have wrapper process or systemd acting as
// subreaper.
if err := utils.SetSubreaper(1); err != nil {
return nil, fmt.Errorf("failed to set server as subreaper: %v", err)
}
utils.StartReaper()
if err := os.MkdirAll(config.ImageDir, 0755); err != nil {
return nil, err
}

View file

@ -6,7 +6,6 @@ import (
"io"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
"syscall"
@ -14,9 +13,6 @@ import (
"github.com/Sirupsen/logrus"
)
// PRSetChildSubreaper is the value of PR_SET_CHILD_SUBREAPER in prctl(2)
const PRSetChildSubreaper = 36
// ExecCmd executes a command with args and returns its output as a string along
// with an error, if any
func ExecCmd(name string, args ...string) (string, error) {
@ -49,11 +45,6 @@ func ExecCmdWithStdStreams(stdin io.Reader, stdout, stderr io.Writer, name strin
return nil
}
// SetSubreaper sets the value i as the subreaper setting for the calling process
func SetSubreaper(i int) error {
return Prctl(PRSetChildSubreaper, uintptr(i), 0, 0, 0)
}
// Prctl is a way to make the prctl linux syscall
func Prctl(option int, arg2, arg3, arg4, arg5 uintptr) (err error) {
_, _, e1 := syscall.Syscall6(syscall.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0)
@ -135,40 +126,6 @@ func dockerRemove(container string) error {
return err
}
// StartReaper starts a goroutine to reap processes
func StartReaper() {
logrus.Infof("Starting reaper")
go func() {
sigs := make(chan os.Signal, 10)
signal.Notify(sigs, syscall.SIGCHLD)
for {
// Wait for a child to terminate
sig := <-sigs
for {
// Reap processes
var status syscall.WaitStatus
cpid, err := syscall.Wait4(-1, &status, syscall.WNOHANG, nil)
if err != nil {
if err != syscall.ECHILD {
logrus.Debugf("wait4 after %v: %v", sig, err)
}
break
}
if cpid < 1 {
break
}
if status.Exited() {
logrus.Debugf("Reaped process with pid %d, exited with status %d", cpid, status.ExitStatus())
} else if status.Signaled() {
logrus.Debugf("Reaped process with pid %d, exited on %s", cpid, status.Signal())
} else {
logrus.Debugf("Reaped process with pid %d", cpid)
}
}
}
}()
}
// StatusToExitCode converts wait status code to an exit code
func StatusToExitCode(status int) int {
return ((status) & 0xff00) >> 8