diff --git a/nsinit/execin.go b/nsinit/execin.go index 306250cf..253fbdce 100644 --- a/nsinit/execin.go +++ b/nsinit/execin.go @@ -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 diff --git a/nsinit/nsinit/main.go b/nsinit/nsinit/main.go index e385e7fb..e6b020b7 100644 --- a/nsinit/nsinit/main.go +++ b/nsinit/nsinit/main.go @@ -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 } diff --git a/nsinit/state.go b/nsinit/state.go index 5c719e1c..af38008c 100644 --- a/nsinit/state.go +++ b/nsinit/state.go @@ -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")) }