mirror of
https://github.com/opencontainers/runc.git
synced 2025-09-26 19:41:35 +08:00

StartInitialization does not have to be a method of Factory (while it is clear why it was done that way initially, now we only have Linux containers so it does not make sense). Fix callers and docs accordingly. No change in functionality. Also, since this was the only user of libcontainer.New with the empty string as an argument, the corresponding check can now be removed from it. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"strconv"
|
|
|
|
"github.com/opencontainers/runc/libcontainer"
|
|
_ "github.com/opencontainers/runc/libcontainer/nsenter"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func init() {
|
|
if len(os.Args) > 1 && os.Args[1] == "init" {
|
|
// This is the golang entry point for runc init, executed
|
|
// before main() but after libcontainer/nsenter's nsexec().
|
|
runtime.GOMAXPROCS(1)
|
|
runtime.LockOSThread()
|
|
|
|
level, err := strconv.Atoi(os.Getenv("_LIBCONTAINER_LOGLEVEL"))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
logPipeFd, err := strconv.Atoi(os.Getenv("_LIBCONTAINER_LOGPIPE"))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
logrus.SetLevel(logrus.Level(level))
|
|
logrus.SetOutput(os.NewFile(uintptr(logPipeFd), "logpipe"))
|
|
logrus.SetFormatter(new(logrus.JSONFormatter))
|
|
logrus.Debug("child process in init()")
|
|
|
|
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)
|
|
}
|
|
panic("libcontainer: container init failed to exec")
|
|
}
|
|
}
|