diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 2e6c83db..3fd97a4a 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -40,6 +40,7 @@ type linuxContainer struct { config *configs.Config cgroupManager cgroups.Manager intelRdtManager intelrdt.Manager + initPath string initArgs []string initProcess parentProcess initProcessStartTime uint64 @@ -413,7 +414,8 @@ 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.Command(c.initPath, c.initArgs[1:]...) + cmd.Args[0] = c.initArgs[0] cmd.Stdin = p.Stdin cmd.Stdout = p.Stdout cmd.Stderr = p.Stderr diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index 83aeb8f1..a409abce 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -134,7 +134,8 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) { } l := &LinuxFactory{ Root: root, - InitArgs: []string{"/proc/self/exe", "init"}, + InitPath: "/proc/self/exe", + InitArgs: []string{os.Args[0], "init"}, Validator: validate.New(), CriuPath: "criu", } @@ -155,6 +156,10 @@ type LinuxFactory struct { // Root directory for the factory to store state. Root string + // InitPath is the path for calling the init responsibilities for spawning + // a container. + InitPath string + // InitArgs are arguments for calling the init responsibilities for spawning // a container. InitArgs []string @@ -207,6 +212,7 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err id: id, root: containerRoot, config: config, + initPath: l.InitPath, initArgs: l.InitArgs, criuPath: l.CriuPath, newuidmapPath: l.NewuidmapPath, @@ -243,6 +249,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) { initProcessStartTime: state.InitProcessStartTime, id: id, config: &state.Config, + initPath: l.InitPath, initArgs: l.InitArgs, criuPath: l.CriuPath, newuidmapPath: l.NewuidmapPath,