diff --git a/state.go b/configs/state.go similarity index 98% rename from state.go rename to configs/state.go index 4ab47ad75..9dc770067 100644 --- a/state.go +++ b/configs/state.go @@ -1,4 +1,4 @@ -package libcontainer +package configs import ( "encoding/json" diff --git a/container.go b/container.go index c0bafa5d7..e04a43df4 100644 --- a/container.go +++ b/container.go @@ -21,7 +21,7 @@ type Container interface { // errors: // ContainerDestroyed - Container no longer exists, // Systemerror - System error. - RunState() (RunState, error) + RunState() (configs.RunState, error) // Returns the current config of the container. Config() *configs.Config diff --git a/linux_container.go b/linux_container.go index d733cb79d..99cea6335 100644 --- a/linux_container.go +++ b/linux_container.go @@ -19,7 +19,7 @@ type linuxContainer struct { id string root string config *configs.Config - state *State + state *configs.State cgroupManager CgroupManager initArgs []string } @@ -32,8 +32,8 @@ func (c *linuxContainer) Config() *configs.Config { return c.config } -func (c *linuxContainer) RunState() (RunState, error) { - return Destroyed, nil // FIXME return a real state +func (c *linuxContainer) RunState() (configs.RunState, error) { + return configs.Destroyed, nil // FIXME return a real state } func (c *linuxContainer) Processes() ([]int, error) { @@ -61,18 +61,18 @@ func (c *linuxContainer) Stats() (*ContainerStats, error) { return stats, nil } -func (c *linuxContainer) StartProcess(config *ProcessConfig) (int, error) { +func (c *linuxContainer) StartProcess(pconfig *ProcessConfig) (int, error) { state, err := c.RunState() if err != nil { return -1, err } - if state != Destroyed { + if state != configs.Destroyed { glog.Info("start new container process") panic("not implemented") } - if err := c.startInitProcess(config); err != nil { + if err := c.startInitProcess(pconfig); err != nil { return -1, err } @@ -141,7 +141,7 @@ func (c *linuxContainer) Destroy() error { return err } - if state != Destroyed { + if state != configs.Destroyed { return newGenericError(nil, ContainerNotStopped) } diff --git a/linux_container_test.go b/linux_container_test.go index 6771a824d..64d4fb8bc 100644 --- a/linux_container_test.go +++ b/linux_container_test.go @@ -53,7 +53,7 @@ func TestGetContainerStats(t *testing.T) { }, }, }, - state: &State{}, + state: &configs.State{}, } stats, err := container.Stats() diff --git a/linux_factory.go b/linux_factory.go index 5d5d097ce..5dc679bdc 100644 --- a/linux_factory.go +++ b/linux_factory.go @@ -93,7 +93,7 @@ func (l *linuxFactory) Create(id string, config *configs.Config) (Container, err root: containerRoot, config: config, initArgs: l.initArgs, - state: &State{}, + state: &configs.State{}, cgroupManager: cgroupManager, }, nil } @@ -144,7 +144,7 @@ func (l *linuxFactory) loadContainerConfig(root string) (*configs.Config, error) return config, nil } -func (l *linuxFactory) loadContainerState(root string) (*State, error) { +func (l *linuxFactory) loadContainerState(root string) (*configs.State, error) { f, err := os.Open(filepath.Join(root, stateFilename)) if err != nil { if os.IsNotExist(err) { @@ -154,7 +154,7 @@ func (l *linuxFactory) loadContainerState(root string) (*State, error) { } defer f.Close() - var state *State + var state *configs.State if err := json.NewDecoder(f).Decode(&state); err != nil { return nil, newGenericError(err, SystemError) } diff --git a/linux_factory_test.go b/linux_factory_test.go index 51986d394..3c1e275c0 100644 --- a/linux_factory_test.go +++ b/linux_factory_test.go @@ -88,7 +88,7 @@ func TestFactoryLoadContainer(t *testing.T) { expectedConfig = &configs.Config{ RootFs: "/mycontainer/root", } - expectedState = &State{ + expectedState = &configs.State{ InitPid: 1024, } ) diff --git a/namespaces/exec.go b/namespaces/exec.go index 63ade9167..32b9ab126 100644 --- a/namespaces/exec.go +++ b/namespaces/exec.go @@ -9,7 +9,6 @@ import ( "os/exec" "syscall" - "github.com/docker/libcontainer" "github.com/docker/libcontainer/cgroups" "github.com/docker/libcontainer/cgroups/fs" "github.com/docker/libcontainer/cgroups/systemd" @@ -80,17 +79,17 @@ func Exec(container *configs.Config, stdin io.Reader, stdout, stderr io.Writer, return terminate(err) } - state := &libcontainer.State{ + state := &configs.State{ InitPid: command.Process.Pid, InitStartTime: started, NetworkState: networkState, CgroupPaths: cgroupPaths, } - if err := libcontainer.SaveState(dataPath, state); err != nil { + if err := configs.SaveState(dataPath, state); err != nil { return terminate(err) } - defer libcontainer.DeleteState(dataPath) + defer configs.DeleteState(dataPath) // wait for the child process to fully complete and receive an error message // if one was encoutered diff --git a/namespaces/execin.go b/namespaces/execin.go index 8b642fd3a..2b63b8c6f 100644 --- a/namespaces/execin.go +++ b/namespaces/execin.go @@ -12,7 +12,6 @@ import ( "strconv" "syscall" - "github.com/docker/libcontainer" "github.com/docker/libcontainer/apparmor" "github.com/docker/libcontainer/cgroups" "github.com/docker/libcontainer/configs" @@ -22,7 +21,7 @@ import ( // ExecIn reexec's the initPath with the argv 0 rewrite to "nsenter" so that it is able to run the // setns code in a single threaded environment joining the existing containers' namespaces. -func ExecIn(container *configs.Config, state *libcontainer.State, userArgs []string, initPath, action string, +func ExecIn(container *configs.Config, state *configs.State, userArgs []string, initPath, action string, stdin io.Reader, stdout, stderr io.Writer, console string, startCallback func(*exec.Cmd)) (int, error) { args := []string{fmt.Sprintf("nsenter-%s", action), "--nspid", strconv.Itoa(state.InitPid)} @@ -119,6 +118,6 @@ func FinalizeSetns(container *configs.Config, args []string) error { panic("unreachable") } -func EnterCgroups(state *libcontainer.State, pid int) error { +func EnterCgroups(state *configs.State, pid int) error { return cgroups.EnterPid(state.CgroupPaths, pid) } diff --git a/nsinit/exec.go b/nsinit/exec.go index a5fd29cbb..8e0e734f2 100644 --- a/nsinit/exec.go +++ b/nsinit/exec.go @@ -111,7 +111,7 @@ func execAction(context *cli.Context) { // with the nsenter argument so that the C code can setns an the namespaces that we require. Then that // code path will drop us into the path that we can do the final setup of the namespace and exec the users // application. -func startInExistingContainer(config *configs.Config, state *libcontainer.State, action string, context *cli.Context) (int, error) { +func startInExistingContainer(config *configs.Config, state *configs.State, action string, context *cli.Context) (int, error) { var ( master *os.File console string