github.com/hernad/nomad@v1.6.112/drivers/shared/executor/libcontainer_nsenter_linux.go (about)

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