From cc33cd34103669cac903d7f906c26287360f40ba Mon Sep 17 00:00:00 2001 From: Michael Crosby <michael@crosbymichael.com> Date: Wed, 30 Apr 2014 18:20:01 -0700 Subject: [PATCH] Integrate new structure into docker's native driver This duplicates some of the Exec code but I think it it worth it because the native driver is more straight forward and does not have the complexity have handling the type issues for now. Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael) --- libcontainer/nsinit/exec.go | 23 ----------------------- libcontainer/nsinit/pid.go | 28 ++++++++++++++++++++++++++++ libcontainer/nsinit/unsupported.go | 13 +++++++++++++ system/unsupported.go | 5 +++++ 4 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 libcontainer/nsinit/pid.go diff --git a/libcontainer/nsinit/exec.go b/libcontainer/nsinit/exec.go index 5aa98af..078f277 100644 --- a/libcontainer/nsinit/exec.go +++ b/libcontainer/nsinit/exec.go @@ -3,11 +3,8 @@ package nsinit import ( - "fmt" - "io/ioutil" "os" "os/exec" - "path/filepath" "syscall" "github.com/dotcloud/docker/pkg/cgroups" @@ -160,26 +157,6 @@ func InitializeNetworking(container *libcontainer.Container, nspid int, pipe *Sy return pipe.SendToChild(context) } -// WritePid writes the namespaced processes pid to pid and it's start time -// to the path specified -func WritePid(path string, pid int, startTime string) error { - err := ioutil.WriteFile(filepath.Join(path, "pid"), []byte(fmt.Sprint(pid)), 0655) - if err != nil { - return err - } - return ioutil.WriteFile(filepath.Join(path, "start"), []byte(startTime), 0655) -} - -// DeletePid removes the pid and started file from disk when the container's process -// dies and the container is cleanly removed -func DeletePid(path string) error { - err := os.Remove(filepath.Join(path, "pid")) - if serr := os.Remove(filepath.Join(path, "start")); err == nil { - err = serr - } - return err -} - // GetNamespaceFlags parses the container's Namespaces options to set the correct // flags on clone, unshare, and setns func GetNamespaceFlags(namespaces libcontainer.Namespaces) (flag int) { diff --git a/libcontainer/nsinit/pid.go b/libcontainer/nsinit/pid.go new file mode 100644 index 0000000..bba2f10 --- /dev/null +++ b/libcontainer/nsinit/pid.go @@ -0,0 +1,28 @@ +package nsinit + +import ( + "fmt" + "io/ioutil" + "os" + "path/filepath" +) + +// WritePid writes the namespaced processes pid to pid and it's start time +// to the path specified +func WritePid(path string, pid int, startTime string) error { + err := ioutil.WriteFile(filepath.Join(path, "pid"), []byte(fmt.Sprint(pid)), 0655) + if err != nil { + return err + } + return ioutil.WriteFile(filepath.Join(path, "start"), []byte(startTime), 0655) +} + +// DeletePid removes the pid and started file from disk when the container's process +// dies and the container is cleanly removed +func DeletePid(path string) error { + err := os.Remove(filepath.Join(path, "pid")) + if serr := os.Remove(filepath.Join(path, "start")); err == nil { + err = serr + } + return err +} diff --git a/libcontainer/nsinit/unsupported.go b/libcontainer/nsinit/unsupported.go index 972d905..c99d881 100644 --- a/libcontainer/nsinit/unsupported.go +++ b/libcontainer/nsinit/unsupported.go @@ -3,9 +3,22 @@ package nsinit import ( + "github.com/dotcloud/docker/pkg/cgroups" "github.com/dotcloud/docker/pkg/libcontainer" ) +func Init(container *libcontainer.Container, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error { + return libcontainer.ErrUnsupported +} + +func InitializeNetworking(container *libcontainer.Container, nspid int, pipe *SyncPipe) error { + return libcontainer.ErrUnsupported +} + +func SetupCgroups(container *libcontainer.Container, nspid int) (cgroups.ActiveCgroup, error) { + return nil, libcontainer.ErrUnsupported +} + func GetNamespaceFlags(namespaces libcontainer.Namespaces) (flag int) { return 0 } diff --git a/system/unsupported.go b/system/unsupported.go index 4ae2a48..96ebc85 100644 --- a/system/unsupported.go +++ b/system/unsupported.go @@ -3,6 +3,7 @@ package system import ( + "os" "os/exec" ) @@ -23,3 +24,7 @@ func GetClockTicks() int { // just return 100 return 100 } + +func CreateMasterAndConsole() (*os.File, string, error) { + return nil, "", ErrNotSupportedPlatform +}