Thanks to visit codestin.com
Credit goes to github.com

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: 2 additions & 1 deletion oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit: This change isn't really needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems a gofmt problem, I have create a commit to add a check in CI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm pretty sure I'm running gofmt with vim, will double check, thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@runcom yeah, I mean you are right in this PR, this is a gofmt problem brought before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright then

"golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/fields"
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
43 changes: 0 additions & 43 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import (
"io"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
"syscall"

"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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down