From 630c0d7e8ca8affbf687988365b53a03bc6980e1 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 26 Jan 2022 20:50:20 -0800 Subject: [PATCH] libct: Container, Factory: rm InitPath, InitArgs Those are *always* /proc/self/exe init, and it does not make sense to ever change these. More to say, if InitArgs option func (removed by this commit) is used to change these parameters, it will break things, since "init" is hardcoded elsewhere. Remove this. Signed-off-by: Kir Kolyshkin --- libcontainer/README.md | 2 +- libcontainer/container_linux.go | 6 ++---- libcontainer/factory_linux.go | 34 --------------------------------- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/libcontainer/README.md b/libcontainer/README.md index 658eb4313..79388eaf0 100644 --- a/libcontainer/README.md +++ b/libcontainer/README.md @@ -45,7 +45,7 @@ Then to create a container you first have to initialize an instance of a factory that will handle the creation and initialization for a container. ```go -factory, err := libcontainer.New("/var/lib/container", libcontainer.InitArgs(os.Args[0], "init")) +factory, err := libcontainer.New("/var/lib/container") if err != nil { logrus.Fatal(err) return diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 91bea2a33..6e0a5cefe 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -41,8 +41,6 @@ type linuxContainer struct { config *configs.Config cgroupManager cgroups.Manager intelRdtManager intelrdt.Manager - initPath string - initArgs []string initProcess parentProcess initProcessStartTime uint64 newuidmapPath string @@ -481,8 +479,8 @@ func (c *linuxContainer) newParentProcess(p *Process) (parentProcess, error) { } func (c *linuxContainer) commandTemplate(p *Process, childInitPipe *os.File, childLogPipe *os.File) *exec.Cmd { - cmd := exec.Command(c.initPath, c.initArgs[1:]...) - cmd.Args[0] = c.initArgs[0] + cmd := exec.Command("/proc/self/exe", "init") + cmd.Args[0] = os.Args[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 d72a0532c..13dbeea67 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "os" - "path/filepath" "regexp" "runtime/debug" "strconv" @@ -29,25 +28,6 @@ const ( var idRegex = regexp.MustCompile(`^[\w+-\.]+$`) -// InitArgs returns an options func to configure a LinuxFactory with the -// provided init binary path and arguments. -func InitArgs(args ...string) func(*LinuxFactory) error { - return func(l *LinuxFactory) (err error) { - if len(args) > 0 { - // Resolve relative paths to ensure that its available - // after directory changes. - if args[0], err = filepath.Abs(args[0]); err != nil { - // The only error returned from filepath.Abs is - // the one from os.Getwd, i.e. a system error. - return err - } - } - - l.InitArgs = args - return nil - } -} - // IntelRdtfs is an options func to configure a LinuxFactory to return // containers that use the Intel RDT "resource control" filesystem to // create and manage Intel RDT resources (e.g., L3 cache, memory bandwidth). @@ -86,8 +66,6 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) { } l := &LinuxFactory{ Root: root, - InitPath: "/proc/self/exe", - InitArgs: []string{os.Args[0], "init"}, Validator: validate.New(), } @@ -107,14 +85,6 @@ 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 - // New{u,g}idmapPath is the path to the binaries used for mapping with // rootless containers. NewuidmapPath string @@ -188,8 +158,6 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err id: id, root: containerRoot, config: config, - initPath: l.InitPath, - initArgs: l.InitArgs, newuidmapPath: l.NewuidmapPath, newgidmapPath: l.NewgidmapPath, cgroupManager: cm, @@ -231,8 +199,6 @@ func (l *LinuxFactory) Load(id string) (Container, error) { initProcessStartTime: state.InitProcessStartTime, id: id, config: &state.Config, - initPath: l.InitPath, - initArgs: l.InitArgs, newuidmapPath: l.NewuidmapPath, newgidmapPath: l.NewgidmapPath, cgroupManager: cm,