1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Persistent directory for container in execdriver

This is needed for persistent namespaces

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>
This commit is contained in:
Alexandr Morozov 2014-09-10 11:34:38 +04:00 committed by Alexandr Morozov
parent 06d0853682
commit 623ebf203b
4 changed files with 20 additions and 7 deletions

View file

@ -115,6 +115,10 @@ func (daemon *Daemon) Destroy(container *Container) error {
return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err) return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err)
} }
if err := daemon.execDriver.Clean(container.ID); err != nil {
return fmt.Errorf("Unable to remove execdriver data for %s: %s", container.ID, err)
}
selinuxFreeLxcContexts(container.ProcessLabel) selinuxFreeLxcContexts(container.ProcessLabel)
return nil return nil

View file

@ -51,6 +51,7 @@ type Driver interface {
Info(id string) Info // "temporary" hack (until we move state from core to plugins) Info(id string) Info // "temporary" hack (until we move state from core to plugins)
GetPidsForContainer(id string) ([]int, error) // Returns a list of pids for the given container. GetPidsForContainer(id string) ([]int, error) // Returns a list of pids for the given container.
Terminate(c *Command) error // kill it with fire Terminate(c *Command) error // kill it with fire
Clean(id string) error // clean all traces of container exec
} }
// Network settings of the container // Network settings of the container

View file

@ -457,6 +457,11 @@ func (d *driver) generateEnvConfig(c *execdriver.Command) error {
return ioutil.WriteFile(p, data, 0600) return ioutil.WriteFile(p, data, 0600)
} }
// Clean not implemented for lxc
func (d *driver) Clean(id string) error {
return nil
}
type TtyConsole struct { type TtyConsole struct {
MasterPty *os.File MasterPty *os.File
SlavePty *os.File SlavePty *os.File

View file

@ -94,7 +94,7 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
if err := d.createContainerRoot(c.ID); err != nil { if err := d.createContainerRoot(c.ID); err != nil {
return -1, err return -1, err
} }
defer d.removeContainerRoot(c.ID) defer d.cleanContainer(c.ID)
if err := d.writeContainerFile(container, c.ID); err != nil { if err := d.writeContainerFile(container, c.ID); err != nil {
return -1, err return -1, err
@ -186,7 +186,7 @@ func (d *driver) Terminate(p *execdriver.Command) error {
err = syscall.Kill(p.ProcessConfig.Process.Pid, 9) err = syscall.Kill(p.ProcessConfig.Process.Pid, 9)
syscall.Wait4(p.ProcessConfig.Process.Pid, nil, 0, nil) syscall.Wait4(p.ProcessConfig.Process.Pid, nil, 0, nil)
} }
d.removeContainerRoot(p.ID) d.cleanContainer(p.ID)
return err return err
@ -227,15 +227,18 @@ func (d *driver) writeContainerFile(container *libcontainer.Config, id string) e
return ioutil.WriteFile(filepath.Join(d.root, id, "container.json"), data, 0655) return ioutil.WriteFile(filepath.Join(d.root, id, "container.json"), data, 0655)
} }
func (d *driver) cleanContainer(id string) error {
d.Lock()
delete(d.activeContainers, id)
d.Unlock()
return os.RemoveAll(filepath.Join(d.root, id, "container.json"))
}
func (d *driver) createContainerRoot(id string) error { func (d *driver) createContainerRoot(id string) error {
return os.MkdirAll(filepath.Join(d.root, id), 0655) return os.MkdirAll(filepath.Join(d.root, id), 0655)
} }
func (d *driver) removeContainerRoot(id string) error { func (d *driver) Clean(id string) error {
d.Lock()
delete(d.activeContainers, id)
d.Unlock()
return os.RemoveAll(filepath.Join(d.root, id)) return os.RemoveAll(filepath.Join(d.root, id))
} }