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:
parent
9f4c15e978
commit
383636e03d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue