From cb21c10a7edcef5a8291a8de9f469ed5bba823af Mon Sep 17 00:00:00 2001 From: Rico Pahlisch Date: Wed, 10 Jun 2026 14:31:51 +0200 Subject: [PATCH] fix: handle initMount helper completion initMount helpers return from StartInitialization without exec'ing after completing their work. Avoid sending a nil procError payload on successful helper completion and exit cleanly from the init command instead of panicking. Signed-off-by: Rico Pahlisch --- init.go | 10 ++++++++-- libcontainer/factory_linux.go | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/init.go b/init.go index 335f80a70..ffd20f78c 100644 --- a/init.go +++ b/init.go @@ -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") }, } diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index 8e5e1f9e5..57195bc23 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -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