diff --git a/daemon/daemon.go b/daemon/daemon.go index 434b78a339..fb3932a0e0 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -1015,7 +1015,7 @@ func NewDaemonFromDirectory(config *Config, eng *engine.Engine) (*Daemon, error) sysInfo := sysinfo.New(false) const runDir = "/var/run/docker" - ed, err := execdrivers.NewDriver(config.ExecDriver, runDir, sysInitPath, sysInfo) + ed, err := execdrivers.NewDriver(config.ExecDriver, runDir, config.Root, sysInitPath, sysInfo) if err != nil { return nil, err } diff --git a/daemon/execdriver/execdrivers/execdrivers.go b/daemon/execdriver/execdrivers/execdrivers.go index be3222a8b4..f6f97c9302 100644 --- a/daemon/execdriver/execdrivers/execdrivers.go +++ b/daemon/execdriver/execdrivers/execdrivers.go @@ -10,13 +10,13 @@ import ( "github.com/docker/docker/pkg/sysinfo" ) -func NewDriver(name, root, initPath string, sysInfo *sysinfo.SysInfo) (execdriver.Driver, error) { +func NewDriver(name, root, libPath, initPath string, sysInfo *sysinfo.SysInfo) (execdriver.Driver, error) { switch name { case "lxc": // we want to give the lxc driver the full docker root because it needs // to access and write config and template files in /var/lib/docker/containers/* // to be backwards compatible - return lxc.NewDriver(root, initPath, sysInfo.AppArmor) + return lxc.NewDriver(root, libPath, initPath, sysInfo.AppArmor) case "native": return native.NewDriver(path.Join(root, "execdriver", "native"), initPath) } diff --git a/daemon/execdriver/lxc/driver.go b/daemon/execdriver/lxc/driver.go index 353e6acef7..55c4ac4e14 100644 --- a/daemon/execdriver/lxc/driver.go +++ b/daemon/execdriver/lxc/driver.go @@ -36,6 +36,7 @@ var ErrExec = errors.New("Unsupported: Exec is not supported by the lxc driver") type driver struct { root string // root path for the driver to use + libPath string initPath string apparmor bool sharedRoot bool @@ -49,7 +50,7 @@ type activeContainer struct { cmd *exec.Cmd } -func NewDriver(root, initPath string, apparmor bool) (*driver, error) { +func NewDriver(root, libPath, initPath string, apparmor bool) (*driver, error) { if err := os.MkdirAll(root, 0700); err != nil { return nil, err } @@ -64,6 +65,7 @@ func NewDriver(root, initPath string, apparmor bool) (*driver, error) { return &driver{ apparmor: apparmor, root: root, + libPath: libPath, initPath: initPath, sharedRoot: rootIsShared(), activeContainers: make(map[string]*activeContainer), @@ -669,7 +671,7 @@ func rootIsShared() bool { } func (d *driver) containerDir(containerId string) string { - return path.Join(d.root, "containers", containerId) + return path.Join(d.libPath, "containers", containerId) } func (d *driver) generateLXCConfig(c *execdriver.Command) (string, error) { @@ -699,7 +701,7 @@ func (d *driver) generateEnvConfig(c *execdriver.Command) error { if err != nil { return err } - p := path.Join(d.root, "containers", c.ID, "config.env") + p := path.Join(d.libPath, "containers", c.ID, "config.env") c.Mounts = append(c.Mounts, execdriver.Mount{ Source: p, Destination: "/.dockerenv", @@ -791,5 +793,8 @@ func (d *driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessCo } func (d *driver) Stats(id string) (*execdriver.ResourceStats, error) { + if _, ok := d.activeContainers[id]; !ok { + return nil, fmt.Errorf("%s is not a key in active containers", id) + } return execdriver.Stats(d.containerDir(id), d.activeContainers[id].container.Cgroups.Memory, d.machineMemory) } diff --git a/daemon/execdriver/lxc/lxc_template_unit_test.go b/daemon/execdriver/lxc/lxc_template_unit_test.go index 65e7b6d551..78760f6007 100644 --- a/daemon/execdriver/lxc/lxc_template_unit_test.go +++ b/daemon/execdriver/lxc/lxc_template_unit_test.go @@ -39,7 +39,7 @@ func TestLXCConfig(t *testing.T) { cpu = cpuMin + rand.Intn(cpuMax-cpuMin) ) - driver, err := NewDriver(root, "", false) + driver, err := NewDriver(root, root, "", false) if err != nil { t.Fatal(err) } @@ -76,7 +76,7 @@ func TestCustomLxcConfig(t *testing.T) { os.MkdirAll(path.Join(root, "containers", "1"), 0777) - driver, err := NewDriver(root, "", false) + driver, err := NewDriver(root, root, "", false) if err != nil { t.Fatal(err) } @@ -194,7 +194,7 @@ func TestCustomLxcConfigMounts(t *testing.T) { } os.MkdirAll(path.Join(root, "containers", "1"), 0777) - driver, err := NewDriver(root, "", false) + driver, err := NewDriver(root, root, "", false) if err != nil { t.Fatal(err) } @@ -248,7 +248,7 @@ func TestCustomLxcConfigMisc(t *testing.T) { } defer os.RemoveAll(root) os.MkdirAll(path.Join(root, "containers", "1"), 0777) - driver, err := NewDriver(root, "", true) + driver, err := NewDriver(root, root, "", true) if err != nil { t.Fatal(err) @@ -313,7 +313,7 @@ func TestCustomLxcConfigMiscOverride(t *testing.T) { } defer os.RemoveAll(root) os.MkdirAll(path.Join(root, "containers", "1"), 0777) - driver, err := NewDriver(root, "", false) + driver, err := NewDriver(root, root, "", false) if err != nil { t.Fatal(err) }