2019-03-18 21:36:31 +00:00
|
|
|
package executor
|
2018-09-24 18:37:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/opencontainers/runc/libcontainer"
|
|
|
|
_ "github.com/opencontainers/runc/libcontainer/nsenter"
|
|
|
|
)
|
|
|
|
|
|
|
|
// init is only run on linux and is used when the LibcontainerExecutor starts
|
|
|
|
// a new process. The libcontainer shim takes over the process, setting up the
|
|
|
|
// configured isolation and limitions before execve into the user process
|
2019-04-19 13:45:50 +00:00
|
|
|
//
|
|
|
|
// This subcommand handler is implemented as an `init`, libcontainer shim is handled anywhere
|
|
|
|
// this package is used (including tests) without needing to write special command handler.
|
2018-09-24 18:37:45 +00:00
|
|
|
func init() {
|
|
|
|
if len(os.Args) > 1 && os.Args[1] == "libcontainer-shim" {
|
|
|
|
runtime.GOMAXPROCS(1)
|
|
|
|
runtime.LockOSThread()
|
|
|
|
factory, _ := libcontainer.New("")
|
|
|
|
if err := factory.StartInitialization(); err != nil {
|
|
|
|
hclog.L().Error("failed to initialize libcontainer-shim", "error", err)
|
2019-03-12 01:57:21 +00:00
|
|
|
os.Exit(1)
|
2018-09-24 18:37:45 +00:00
|
|
|
}
|
|
|
|
panic("--this line should have never been executed, congratulations--")
|
|
|
|
}
|
|
|
|
}
|