Merge pull request #934 from macrosheep/fix-initargs
Fix and refactor init args
This commit is contained in:
commit
46d9535096
|
@ -35,7 +35,6 @@ type linuxContainer struct {
|
||||||
root string
|
root string
|
||||||
config *configs.Config
|
config *configs.Config
|
||||||
cgroupManager cgroups.Manager
|
cgroupManager cgroups.Manager
|
||||||
initPath string
|
|
||||||
initArgs []string
|
initArgs []string
|
||||||
initProcess parentProcess
|
initProcess parentProcess
|
||||||
initProcessStartTime string
|
initProcessStartTime string
|
||||||
|
@ -308,10 +307,7 @@ func (c *linuxContainer) newParentProcess(p *Process, doInit bool) (parentProces
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *linuxContainer) commandTemplate(p *Process, childPipe, rootDir *os.File) (*exec.Cmd, error) {
|
func (c *linuxContainer) commandTemplate(p *Process, childPipe, rootDir *os.File) (*exec.Cmd, error) {
|
||||||
cmd := &exec.Cmd{
|
cmd := exec.Command(c.initArgs[0], c.initArgs[1:]...)
|
||||||
Path: c.initPath,
|
|
||||||
Args: c.initArgs,
|
|
||||||
}
|
|
||||||
cmd.Stdin = p.Stdin
|
cmd.Stdin = p.Stdin
|
||||||
cmd.Stdout = p.Stdout
|
cmd.Stdout = p.Stdout
|
||||||
cmd.Stderr = p.Stderr
|
cmd.Stderr = p.Stderr
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
@ -33,32 +32,9 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitArgs returns an options func to configure a LinuxFactory with the
|
// InitArgs returns an options func to configure a LinuxFactory with the
|
||||||
// provided init arguments.
|
// provided init binary path and arguments.
|
||||||
func InitArgs(args ...string) func(*LinuxFactory) error {
|
func InitArgs(args ...string) func(*LinuxFactory) error {
|
||||||
return func(l *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
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
abs, err := filepath.Abs(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
name = abs
|
|
||||||
}
|
|
||||||
l.InitPath = "/proc/self/exe"
|
|
||||||
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
|
l.InitArgs = args
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -122,10 +98,10 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) {
|
||||||
}
|
}
|
||||||
l := &LinuxFactory{
|
l := &LinuxFactory{
|
||||||
Root: root,
|
Root: root,
|
||||||
|
InitArgs: []string{"/proc/self/exe", "init"},
|
||||||
Validator: validate.New(),
|
Validator: validate.New(),
|
||||||
CriuPath: "criu",
|
CriuPath: "criu",
|
||||||
}
|
}
|
||||||
InitArgs(os.Args[0], "init")(l)
|
|
||||||
Cgroupfs(l)
|
Cgroupfs(l)
|
||||||
for _, opt := range options {
|
for _, opt := range options {
|
||||||
if err := opt(l); err != nil {
|
if err := opt(l); err != nil {
|
||||||
|
@ -140,9 +116,6 @@ type LinuxFactory struct {
|
||||||
// Root directory for the factory to store state.
|
// Root directory for the factory to store state.
|
||||||
Root string
|
Root string
|
||||||
|
|
||||||
// InitPath is the absolute path to the init binary.
|
|
||||||
InitPath string
|
|
||||||
|
|
||||||
// InitArgs are arguments for calling the init responsibilities for spawning
|
// InitArgs are arguments for calling the init responsibilities for spawning
|
||||||
// a container.
|
// a container.
|
||||||
InitArgs []string
|
InitArgs []string
|
||||||
|
@ -202,7 +175,6 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
|
||||||
id: id,
|
id: id,
|
||||||
root: containerRoot,
|
root: containerRoot,
|
||||||
config: config,
|
config: config,
|
||||||
initPath: l.InitPath,
|
|
||||||
initArgs: l.InitArgs,
|
initArgs: l.InitArgs,
|
||||||
criuPath: l.CriuPath,
|
criuPath: l.CriuPath,
|
||||||
cgroupManager: l.NewCgroupsManager(config.Cgroups, nil),
|
cgroupManager: l.NewCgroupsManager(config.Cgroups, nil),
|
||||||
|
@ -230,7 +202,6 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
|
||||||
initProcessStartTime: state.InitProcessStartTime,
|
initProcessStartTime: state.InitProcessStartTime,
|
||||||
id: id,
|
id: id,
|
||||||
config: &state.Config,
|
config: &state.Config,
|
||||||
initPath: l.InitPath,
|
|
||||||
initArgs: l.InitArgs,
|
initArgs: l.InitArgs,
|
||||||
criuPath: l.CriuPath,
|
criuPath: l.CriuPath,
|
||||||
cgroupManager: l.NewCgroupsManager(state.Config.Cgroups, state.CgroupPaths),
|
cgroupManager: l.NewCgroupsManager(state.Config.Cgroups, state.CgroupPaths),
|
||||||
|
|
Loading…
Reference in New Issue