mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-09 17:30:06 +08:00

This commit separates the functionality of setting cgroup device rules out of libct/cgroups to libct/cgroups/devices package. This package, if imported, sets the function variables in libct/cgroups and libct/cgroups/systemd, so that a cgroup manager can use those to manage devices. If those function variables are nil (when libct/cgroups/devices are not imported), a cgroup manager returns the ErrDevicesUnsupported in case any device rules are set in Resources. It also consolidates the code from libct/cgroups/ebpf and libct/cgroups/ebpf/devicefilter into libct/cgroups/devices. Moved some tests in libct/cg/sd that require device management to libct/sd/devices. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
36 lines
801 B
Go
36 lines
801 B
Go
package integration
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/opencontainers/runc/libcontainer"
|
|
//nolint:revive // Enable cgroup manager to manage devices
|
|
_ "github.com/opencontainers/runc/libcontainer/cgroups/devices"
|
|
_ "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()
|
|
if err := libcontainer.StartInitialization(); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
logrus.SetOutput(os.Stderr)
|
|
logrus.SetLevel(logrus.InfoLevel)
|
|
|
|
ret := m.Run()
|
|
os.Exit(ret)
|
|
}
|