55 "errors"
66 "fmt"
77 "os"
8- "runtime/debug"
9- "strconv"
108
119 securejoin "github.com/cyphar/filepath-securejoin"
1210 "golang.org/x/sys/unix"
@@ -18,7 +16,6 @@ import (
1816 "github.com/opencontainers/runc/libcontainer/configs/validate"
1917 "github.com/opencontainers/runc/libcontainer/intelrdt"
2018 "github.com/opencontainers/runc/libcontainer/utils"
21- "github.com/sirupsen/logrus"
2219)
2320
2421const (
@@ -151,90 +148,6 @@ func Load(root, id string) (*Container, error) {
151148 return c , nil
152149}
153150
154- // StartInitialization loads a container by opening the pipe fd from the parent
155- // to read the configuration and state. This is a low level implementation
156- // detail of the reexec and should not be consumed externally.
157- func StartInitialization () (err error ) {
158- // Get the INITPIPE.
159- envInitPipe := os .Getenv ("_LIBCONTAINER_INITPIPE" )
160- pipefd , err := strconv .Atoi (envInitPipe )
161- if err != nil {
162- err = fmt .Errorf ("unable to convert _LIBCONTAINER_INITPIPE: %w" , err )
163- logrus .Error (err )
164- return err
165- }
166- pipe := os .NewFile (uintptr (pipefd ), "pipe" )
167- defer pipe .Close ()
168-
169- defer func () {
170- // We have an error during the initialization of the container's init,
171- // send it back to the parent process in the form of an initError.
172- if werr := writeSync (pipe , procError ); werr != nil {
173- fmt .Fprintln (os .Stderr , err )
174- return
175- }
176- if werr := utils .WriteJSON (pipe , & initError {Message : err .Error ()}); werr != nil {
177- fmt .Fprintln (os .Stderr , err )
178- return
179- }
180- }()
181-
182- // Only init processes have FIFOFD.
183- fifofd := - 1
184- envInitType := os .Getenv ("_LIBCONTAINER_INITTYPE" )
185- it := initType (envInitType )
186- if it == initStandard {
187- envFifoFd := os .Getenv ("_LIBCONTAINER_FIFOFD" )
188- if fifofd , err = strconv .Atoi (envFifoFd ); err != nil {
189- return fmt .Errorf ("unable to convert _LIBCONTAINER_FIFOFD: %w" , err )
190- }
191- }
192-
193- var consoleSocket * os.File
194- if envConsole := os .Getenv ("_LIBCONTAINER_CONSOLE" ); envConsole != "" {
195- console , err := strconv .Atoi (envConsole )
196- if err != nil {
197- return fmt .Errorf ("unable to convert _LIBCONTAINER_CONSOLE: %w" , err )
198- }
199- consoleSocket = os .NewFile (uintptr (console ), "console-socket" )
200- defer consoleSocket .Close ()
201- }
202-
203- logPipeFdStr := os .Getenv ("_LIBCONTAINER_LOGPIPE" )
204- logPipeFd , err := strconv .Atoi (logPipeFdStr )
205- if err != nil {
206- return fmt .Errorf ("unable to convert _LIBCONTAINER_LOGPIPE: %w" , err )
207- }
208-
209- // Get mount files (O_PATH).
210- mountFds , err := parseMountFds ()
211- if err != nil {
212- return err
213- }
214-
215- // clear the current process's environment to clean any libcontainer
216- // specific env vars.
217- os .Clearenv ()
218-
219- defer func () {
220- if e := recover (); e != nil {
221- if ee , ok := e .(error ); ok {
222- err = fmt .Errorf ("panic from initialization: %w, %s" , ee , debug .Stack ())
223- } else {
224- err = fmt .Errorf ("panic from initialization: %v, %s" , e , debug .Stack ())
225- }
226- }
227- }()
228-
229- i , err := newContainerInit (it , pipe , consoleSocket , fifofd , logPipeFd , mountFds )
230- if err != nil {
231- return err
232- }
233-
234- // If Init succeeds, syscall.Exec will not return, hence none of the defers will be called.
235- return i .Init ()
236- }
237-
238151func loadState (root string ) (* State , error ) {
239152 stateFilePath , err := securejoin .SecureJoin (root , stateFilename )
240153 if err != nil {
0 commit comments