github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/drivers/shared/executor/libcontainer_nsenter_linux.go (about)

     1  package executor
     2  
     3  import (
     4  	"os"
     5  	"runtime"
     6  
     7  	hclog "github.com/hashicorp/go-hclog"
     8  	"github.com/opencontainers/runc/libcontainer"
     9  	_ "github.com/opencontainers/runc/libcontainer/nsenter"
    10  )
    11  
    12  // init is only run on linux and is used when the LibcontainerExecutor starts
    13  // a new process. The libcontainer shim takes over the process, setting up the
    14  // configured isolation and limitions before execve into the user process
    15  //
    16  // This subcommand handler is implemented as an `init`, libcontainer shim is handled anywhere
    17  // this package is used (including tests) without needing to write special command handler.
    18  func init() {
    19  	if len(os.Args) > 1 && os.Args[1] == "libcontainer-shim" {
    20  		runtime.GOMAXPROCS(1)
    21  		runtime.LockOSThread()
    22  		factory, _ := libcontainer.New("")
    23  		if err := factory.StartInitialization(); err != nil {
    24  			hclog.L().Error("failed to initialize libcontainer-shim", "error", err)
    25  			os.Exit(1)
    26  		}
    27  		panic("--this line should have never been executed, congratulations--")
    28  	}
    29  }