1
0
mirror of https://github.com/opencontainers/runc.git synced 2025-07-04 02:42:31 +03:00
Files
runc/libcontainer/integration/init_test.go
Aleksa Sarai 565325fc36 integration: fix mis-use of libcontainer.Factory
For some reason, libcontainer/integration has a whole bunch of incorrect
usages of libcontainer.Factory -- causing test failures with a set of
security patches that will be published soon. Fixing ths is fairly
trivial (switch to creating a new libcontainer.Factory once in each
process, rather than creating one in TestMain globally).

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2019-01-24 23:12:48 +13:00

47 lines
944 B
Go

package integration
import (
"os"
"runtime"
"testing"
"github.com/opencontainers/runc/libcontainer"
_ "github.com/opencontainers/runc/libcontainer/nsenter"
"github.com/sirupsen/logrus"
)
// init runs the libcontainer initialization code because of the busybox style needs
// to work around the go runtime and the issues with forking
func init() {
if len(os.Args) < 2 || os.Args[1] != "init" {
return
}
runtime.GOMAXPROCS(1)
runtime.LockOSThread()
factory, err := libcontainer.New("")
if err != nil {
logrus.Fatalf("unable to initialize for container: %s", err)
}
if err := factory.StartInitialization(); err != nil {
logrus.Fatal(err)
}
}
var testRoots []string
func TestMain(m *testing.M) {
logrus.SetOutput(os.Stderr)
logrus.SetLevel(logrus.InfoLevel)
// Clean up roots after running everything.
defer func() {
for _, root := range testRoots {
os.RemoveAll(root)
}
}()
ret := m.Run()
os.Exit(ret)
}