server: remove reaper, let runc take care of reaping
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
4cb5af00f6
commit
d2f6a4c0e2
3 changed files with 2 additions and 53 deletions
|
@ -17,8 +17,8 @@ import (
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/kubernetes-incubator/cri-o/utils"
|
|
||||||
"github.com/containernetworking/cni/pkg/ns"
|
"github.com/containernetworking/cni/pkg/ns"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/utils"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
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 {
|
if err != nil && err != syscall.ESRCH {
|
||||||
return fmt.Errorf("failed to kill process: %v", err)
|
return fmt.Errorf("failed to kill process: %v", err)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
// Check if the process is still around
|
// Check if the process is still around
|
||||||
err := unix.Kill(c.state.Pid, 0)
|
err := unix.Kill(c.state.Pid, 0)
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/kubernetes-incubator/cri-o/oci"
|
"github.com/kubernetes-incubator/cri-o/oci"
|
||||||
"github.com/kubernetes-incubator/cri-o/server/apparmor"
|
"github.com/kubernetes-incubator/cri-o/server/apparmor"
|
||||||
"github.com/kubernetes-incubator/cri-o/server/seccomp"
|
"github.com/kubernetes-incubator/cri-o/server/seccomp"
|
||||||
"github.com/kubernetes-incubator/cri-o/utils"
|
|
||||||
"github.com/opencontainers/runc/libcontainer/label"
|
"github.com/opencontainers/runc/libcontainer/label"
|
||||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/rajatchopra/ocicni"
|
"github.com/rajatchopra/ocicni"
|
||||||
|
@ -297,14 +296,6 @@ func seccompEnabled() bool {
|
||||||
|
|
||||||
// New creates a new Server with options provided
|
// New creates a new Server with options provided
|
||||||
func New(config *Config) (*Server, error) {
|
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 {
|
if err := os.MkdirAll(config.ImageDir, 0755); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -14,9 +13,6 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"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
|
// ExecCmd executes a command with args and returns its output as a string along
|
||||||
// with an error, if any
|
// with an error, if any
|
||||||
func ExecCmd(name string, args ...string) (string, error) {
|
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
|
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
|
// Prctl is a way to make the prctl linux syscall
|
||||||
func Prctl(option int, arg2, arg3, arg4, arg5 uintptr) (err error) {
|
func Prctl(option int, arg2, arg3, arg4, arg5 uintptr) (err error) {
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0)
|
_, _, e1 := syscall.Syscall6(syscall.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0)
|
||||||
|
@ -135,40 +126,6 @@ func dockerRemove(container string) error {
|
||||||
return err
|
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
|
// StatusToExitCode converts wait status code to an exit code
|
||||||
func StatusToExitCode(status int) int {
|
func StatusToExitCode(status int) int {
|
||||||
return ((status) & 0xff00) >> 8
|
return ((status) & 0xff00) >> 8
|
||||||
|
|
Loading…
Reference in a new issue