Move process functions to pkg/system

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-12-12 09:28:41 +01:00
parent 0ab9320ab2
commit 8c1ac81665
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3
3 changed files with 11 additions and 12 deletions

View file

@ -21,8 +21,7 @@ import (
"github.com/Sirupsen/logrus"
containerd "github.com/docker/containerd/api/grpc/types"
"github.com/docker/docker/pkg/locker"
sysinfo "github.com/docker/docker/pkg/system"
"github.com/docker/docker/utils"
"github.com/docker/docker/pkg/system"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/timestamp"
"golang.org/x/net/context"
@ -81,7 +80,7 @@ func New(stateDir string, options ...RemoteOption) (_ Remote, err error) {
}
}
if err := sysinfo.MkdirAll(stateDir, 0700); err != nil {
if err := system.MkdirAll(stateDir, 0700); err != nil {
return nil, err
}
@ -164,8 +163,8 @@ func (r *remote) handleConnectionChange() {
transientFailureCount++
if transientFailureCount >= maxConnectionRetryCount {
transientFailureCount = 0
if utils.IsProcessAlive(r.daemonPid) {
utils.KillProcess(r.daemonPid)
if system.IsProcessAlive(r.daemonPid) {
system.KillProcess(r.daemonPid)
}
<-r.daemonWaitCh
if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error
@ -188,13 +187,13 @@ func (r *remote) Cleanup() {
// Wait up to 15secs for it to stop
for i := time.Duration(0); i < containerdShutdownTimeout; i += time.Second {
if !utils.IsProcessAlive(r.daemonPid) {
if !system.IsProcessAlive(r.daemonPid) {
break
}
time.Sleep(time.Second)
}
if utils.IsProcessAlive(r.daemonPid) {
if system.IsProcessAlive(r.daemonPid) {
logrus.Warnf("libcontainerd: containerd (%d) didn't stop within 15 secs, killing it\n", r.daemonPid)
syscall.Kill(r.daemonPid, syscall.SIGKILL)
}
@ -354,7 +353,7 @@ func (r *remote) runContainerdDaemon() error {
if err != nil {
return err
}
if utils.IsProcessAlive(int(pid)) {
if system.IsProcessAlive(int(pid)) {
logrus.Infof("libcontainerd: previous instance of containerd still alive (%d)", pid)
r.daemonPid = int(pid)
return nil
@ -417,11 +416,11 @@ func (r *remote) runContainerdDaemon() error {
}
logrus.Infof("libcontainerd: new containerd process, pid: %d", cmd.Process.Pid)
if err := setOOMScore(cmd.Process.Pid, r.oomScore); err != nil {
utils.KillProcess(cmd.Process.Pid)
system.KillProcess(cmd.Process.Pid)
return err
}
if _, err := f.WriteString(fmt.Sprintf("%d", cmd.Process.Pid)); err != nil {
utils.KillProcess(cmd.Process.Pid)
system.KillProcess(cmd.Process.Pid)
return err
}

View file

@ -1,6 +1,6 @@
// +build linux freebsd solaris
package utils
package system
import (
"syscall"

View file

@ -1,4 +1,4 @@
package utils
package system
// IsProcessAlive returns true if process with a given pid is running.
func IsProcessAlive(pid int) bool {