Move container.json and pid file into a root specific driver dir

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-25 12:41:31 -08:00
parent 9f4c15e978
commit 383636e03d
3 changed files with 11 additions and 9 deletions

View File

@ -42,7 +42,7 @@ func (ns *linuxNs) ExecIn(container *libcontainer.Container, nspid int, args []s
// if the container has a new pid and mount namespace we need to
// remount proc and sys to pick up the changes
if container.Namespaces.Contains("CLONE_NEWNS") && container.Namespaces.Contains("CLONE_NEWPID") {
if container.Namespaces.Contains("NEWNS") && container.Namespaces.Contains("NEWPID") {
pid, err := system.Fork()
if err != nil {
return -1, err

View File

@ -9,12 +9,13 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
)
var (
console string
pipeFd int
root, console string
pipeFd int
)
var (
@ -25,6 +26,7 @@ var (
func registerFlags() {
flag.StringVar(&console, "console", "", "console (pty slave) path")
flag.IntVar(&pipeFd, "pipe", 0, "sync pipe fd")
flag.StringVar(&root, "root", ".", "root for storing configuration data")
flag.Parse()
}
@ -84,7 +86,7 @@ func main() {
}
func loadContainer() (*libcontainer.Container, error) {
f, err := os.Open("container.json")
f, err := os.Open(filepath.Join(root, "container.json"))
if err != nil {
return nil, err
}
@ -98,7 +100,7 @@ func loadContainer() (*libcontainer.Container, error) {
}
func readPid() (int, error) {
data, err := ioutil.ReadFile(".nspid")
data, err := ioutil.ReadFile(filepath.Join(root, "pid"))
if err != nil {
return -1, err
}
@ -110,5 +112,5 @@ func readPid() (int, error) {
}
func newNsInit() (nsinit.NsInit, error) {
return nsinit.NewNsInit(&nsinit.DefaultCommandFactory{}, &nsinit.DefaultStateWriter{}), nil
return nsinit.NewNsInit(&nsinit.DefaultCommandFactory{}, &nsinit.DefaultStateWriter{root}), nil
}

View File

@ -18,11 +18,11 @@ type DefaultStateWriter struct {
Root string
}
// writePidFile writes the namespaced processes pid to .nspid in the rootfs for the container
// writePidFile writes the namespaced processes pid to pid in the rootfs for the container
func (d *DefaultStateWriter) WritePid(pid int) error {
return ioutil.WriteFile(filepath.Join(d.Root, ".nspid"), []byte(fmt.Sprint(pid)), 0655)
return ioutil.WriteFile(filepath.Join(d.Root, "pid"), []byte(fmt.Sprint(pid)), 0655)
}
func (d *DefaultStateWriter) DeletePid() error {
return os.Remove(filepath.Join(d.Root, ".nspid"))
return os.Remove(filepath.Join(d.Root, "pid"))
}