Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ var initCommand = cli.Command{
Name: "init",
Usage: `initialize the namespaces and launch the process (do not call it outside of sysbox-runc)`,
Action: func(context *cli.Context) error {
initType := os.Getenv("_LIBCONTAINER_INITTYPE")

factory, _ := libcontainer.New("")
if err := factory.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)
}

// initMount helpers return here without exec; that's normal.
if initType == "mount" {
os.Exit(0)
}

panic("libcontainer: container init failed to exec")
},
}
6 changes: 6 additions & 0 deletions libcontainer/factory_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ func (l *LinuxFactory) StartInitialization() (err error) {
defer func() {
// We have an error during the initialization of the container's init,
// send it back to the parent process in the form of an initError.
// For initMount helpers, Init() returns nil without exec'ing;
// sending procError with a nil payload would cause the parent's
// parseSync to panic ("No error following JSON procError payload").
if err == nil {
return
}
if werr := utils.WriteJSON(pipe, syncT{procError}); werr != nil {
fmt.Fprintln(os.Stderr, err)
return
Expand Down