diff --git a/container_linux.go b/container_linux.go index a0131280..0b35ded5 100644 --- a/container_linux.go +++ b/container_linux.go @@ -21,6 +21,7 @@ type linuxContainer struct { root string config *configs.Config cgroupManager cgroups.Manager + initPath string initArgs []string initProcess parentProcess m sync.Mutex @@ -120,7 +121,10 @@ func (c *linuxContainer) newParentProcess(p *Process, doInit bool) (parentProces } func (c *linuxContainer) commandTemplate(p *Process, childPipe *os.File) (*exec.Cmd, error) { - cmd := exec.Command(c.initArgs[0], c.initArgs[1:]...) + cmd := &exec.Cmd{ + Path: c.initPath, + Args: c.initArgs, + } cmd.Stdin = p.Stdin cmd.Stdout = p.Stdout cmd.Stderr = p.Stderr diff --git a/factory_linux.go b/factory_linux.go index d0fca3b4..12e072ae 100644 --- a/factory_linux.go +++ b/factory_linux.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" "path/filepath" "regexp" @@ -30,6 +31,23 @@ var ( // provided init arguments. func InitArgs(args ...string) func(*LinuxFactory) error { return func(l *LinuxFactory) error { + name := args[0] + if filepath.Base(name) == name { + if lp, err := exec.LookPath(name); err == nil { + name = lp + } + } + l.InitPath = name + l.InitArgs = append([]string{name}, args[1:]...) + return nil + } +} + +// InitPath returns an options func to configure a LinuxFactory with the +// provided absolute path to the init binary and arguements. +func InitPath(path string, args ...string) func(*LinuxFactory) error { + return func(l *LinuxFactory) error { + l.InitPath = path l.InitArgs = args return nil } @@ -70,7 +88,6 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) { } l := &LinuxFactory{ Root: root, - InitArgs: []string{os.Args[0], "init"}, Validator: validate.New(), } Cgroupfs(l) @@ -87,6 +104,9 @@ type LinuxFactory struct { // Root directory for the factory to store state. Root string + // InitPath is the absolute path to the init binary. + InitPath string + // InitArgs are arguments for calling the init responsibilities for spawning // a container. InitArgs []string @@ -121,6 +141,7 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err id: id, root: containerRoot, config: config, + initPath: l.InitPath, initArgs: l.InitArgs, cgroupManager: l.NewCgroupsManager(config.Cgroups, nil), }, nil @@ -143,6 +164,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) { initProcess: r, id: id, config: &state.Config, + initPath: l.InitPath, initArgs: l.InitArgs, cgroupManager: l.NewCgroupsManager(state.Config.Cgroups, state.CgroupPaths), root: containerRoot,