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
|
// if the container has a new pid and mount namespace we need to
|
||||||
// remount proc and sys to pick up the changes
|
// 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()
|
pid, err := system.Fork()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
|
|
|
@ -9,11 +9,12 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
console string
|
root, console string
|
||||||
pipeFd int
|
pipeFd int
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ var (
|
||||||
func registerFlags() {
|
func registerFlags() {
|
||||||
flag.StringVar(&console, "console", "", "console (pty slave) path")
|
flag.StringVar(&console, "console", "", "console (pty slave) path")
|
||||||
flag.IntVar(&pipeFd, "pipe", 0, "sync pipe fd")
|
flag.IntVar(&pipeFd, "pipe", 0, "sync pipe fd")
|
||||||
|
flag.StringVar(&root, "root", ".", "root for storing configuration data")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
@ -84,7 +86,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadContainer() (*libcontainer.Container, error) {
|
func loadContainer() (*libcontainer.Container, error) {
|
||||||
f, err := os.Open("container.json")
|
f, err := os.Open(filepath.Join(root, "container.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -98,7 +100,7 @@ func loadContainer() (*libcontainer.Container, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readPid() (int, error) {
|
func readPid() (int, error) {
|
||||||
data, err := ioutil.ReadFile(".nspid")
|
data, err := ioutil.ReadFile(filepath.Join(root, "pid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -110,5 +112,5 @@ func readPid() (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNsInit() (nsinit.NsInit, 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
|
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 {
|
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 {
|
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