Skip to content
Snippets Groups Projects
Commit 881684c0 authored by kaiyou's avatar kaiyou
Browse files

Mount self again inside the container

parent fa2919b2
No related branches found
No related tags found
No related merge requests found
......@@ -17,15 +17,21 @@ import (
type Container struct {
config *Config
self string
container libcontainer.Container
process libcontainer.Process
}
// Containerize the current process by runnig the current binary inside a container
func New(config *Config) (*Container, error) {
// Resolve self from the host
self, err := os.Executable()
if err != nil {
return nil, err
}
// Prepare a libcontainer factory using the init path and args
factoryConfig := func(f *libcontainer.LinuxFactory) error {
f.InitPath = "/proc/self/exe"
f.InitPath = self
f.InitArgs = []string{os.Args[0], argInit}
return nil
}
......@@ -34,6 +40,7 @@ func New(config *Config) (*Container, error) {
return nil, err
}
// Create and wrap the libcontainer instance
config.Mounts[self] = self
containerConfig, err := config.toLibcontainer()
if err != nil {
return nil, err
......@@ -44,13 +51,14 @@ func New(config *Config) (*Container, error) {
}
return &Container{
config: config,
self: self,
container: container,
}, nil
}
func (c *Container) Start(args []string) error {
process := libcontainer.Process{
Args: append([]string{"/proc/self/exe"}, args...),
Args: append([]string{c.self}, args...),
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment