diff --git a/init.go b/init.go index bddc237f6..2f44ce8a5 100644 --- a/init.go +++ b/init.go @@ -32,8 +32,7 @@ func init() { logrus.SetFormatter(new(logrus.JSONFormatter)) logrus.Debug("child process in init()") - factory, _ := libcontainer.New("") - if err := factory.StartInitialization(); err != nil { + if err := libcontainer.StartInitialization(); err != nil { // as the error is sent back to the parent there is no need to log // or write it to stderr because the parent process will handle this os.Exit(1) diff --git a/libcontainer/README.md b/libcontainer/README.md index 2850db2aa..4210eacc5 100644 --- a/libcontainer/README.md +++ b/libcontainer/README.md @@ -32,8 +32,7 @@ func init() { if len(os.Args) > 1 && os.Args[1] == "init" { runtime.GOMAXPROCS(1) runtime.LockOSThread() - factory, _ := libcontainer.New("") - if err := factory.StartInitialization(); err != nil { + if err := libcontainer.StartInitialization(); err != nil { logrus.Fatal(err) } panic("--this line should have never been executed, congratulations--") diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index d15a21bac..93dc4812f 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -29,10 +29,8 @@ var idRegex = regexp.MustCompile(`^[\w+-\.]+$`) // New returns a linux based container factory based in the root directory. func New(root string) (*LinuxFactory, error) { - if root != "" { - if err := os.MkdirAll(root, 0o700); err != nil { - return nil, err - } + if err := os.MkdirAll(root, 0o700); err != nil { + return nil, err } return &LinuxFactory{ Root: root, @@ -169,9 +167,10 @@ func (l *LinuxFactory) Load(id string) (Container, error) { return c, nil } -// StartInitialization loads a container by opening the pipe fd from the parent to read the configuration and state -// This is a low level implementation detail of the reexec and should not be consumed externally -func (l *LinuxFactory) StartInitialization() (err error) { +// StartInitialization loads a container by opening the pipe fd from the parent +// to read the configuration and state. This is a low level implementation +// detail of the reexec and should not be consumed externally. +func StartInitialization() (err error) { // Get the INITPIPE. envInitPipe := os.Getenv("_LIBCONTAINER_INITPIPE") pipefd, err := strconv.Atoi(envInitPipe) diff --git a/libcontainer/integration/init_test.go b/libcontainer/integration/init_test.go index effcde06d..b6a3714d4 100644 --- a/libcontainer/integration/init_test.go +++ b/libcontainer/integration/init_test.go @@ -19,11 +19,7 @@ func init() { } runtime.GOMAXPROCS(1) runtime.LockOSThread() - factory, err := libcontainer.New("") - if err != nil { - logrus.Fatalf("unable to initialize for container: %s", err) - } - if err := factory.StartInitialization(); err != nil { + if err := libcontainer.StartInitialization(); err != nil { logrus.Fatal(err) } }