...

Source file src/github.com/opencontainers/runc/init.go

Documentation: github.com/opencontainers/runc

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"runtime"
     6  	"strconv"
     7  
     8  	"github.com/opencontainers/runc/libcontainer"
     9  	_ "github.com/opencontainers/runc/libcontainer/nsenter"
    10  	"github.com/sirupsen/logrus"
    11  )
    12  
    13  func init() {
    14  	if len(os.Args) > 1 && os.Args[1] == "init" {
    15  		// This is the golang entry point for runc init, executed
    16  		// before main() but after libcontainer/nsenter's nsexec().
    17  		runtime.GOMAXPROCS(1)
    18  		runtime.LockOSThread()
    19  
    20  		level, err := strconv.Atoi(os.Getenv("_LIBCONTAINER_LOGLEVEL"))
    21  		if err != nil {
    22  			panic(err)
    23  		}
    24  
    25  		logPipeFd, err := strconv.Atoi(os.Getenv("_LIBCONTAINER_LOGPIPE"))
    26  		if err != nil {
    27  			panic(err)
    28  		}
    29  
    30  		logrus.SetLevel(logrus.Level(level))
    31  		logrus.SetOutput(os.NewFile(uintptr(logPipeFd), "logpipe"))
    32  		logrus.SetFormatter(new(logrus.JSONFormatter))
    33  		logrus.Debug("child process in init()")
    34  
    35  		factory, _ := libcontainer.New("")
    36  		if err := factory.StartInitialization(); err != nil {
    37  			// as the error is sent back to the parent there is no need to log
    38  			// or write it to stderr because the parent process will handle this
    39  			os.Exit(1)
    40  		}
    41  		panic("libcontainer: container init failed to exec")
    42  	}
    43  }
    44  

View as plain text