From 4e1a744b03fbc5318e002a0a105420436992c8c6 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 16 Mar 2023 12:00:39 +0100 Subject: [PATCH 1/2] Use a proper enum to fix CGroupsV2 detection --- cgroup/cgroup.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cgroup/cgroup.go b/cgroup/cgroup.go index 7eac6d0..c4d40f9 100644 --- a/cgroup/cgroup.go +++ b/cgroup/cgroup.go @@ -24,7 +24,7 @@ const ( type CGroupVersion int const ( - CGroupUnknown CGroupVersion = 0 + CGroupUnknown CGroupVersion = iota CGroupV1 CGroupV2 ) @@ -112,8 +112,10 @@ func InitializeDBus(conn *dbus.Conn) { // Check for CGroups v2 if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil { d.cgroupVersion = CGroupV2 + logging.Info.Printf("Detected CGroups Version 2") } else { d.cgroupVersion = CGroupV1 + logging.Info.Printf("Detected CGroups Version 1") } err := conn.Export(d, objectPath, ifaceName) From 55a50dd48366dda8fa92bfacba96c82dfc820ed9 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 16 Mar 2023 12:02:23 +0100 Subject: [PATCH 2/2] Fix argument order in info messages --- cgroup/cgroup.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cgroup/cgroup.go b/cgroup/cgroup.go index c4d40f9..85363e8 100644 --- a/cgroup/cgroup.go +++ b/cgroup/cgroup.go @@ -71,7 +71,7 @@ func (d cgroup) AddDevicesAllowed(containerID string, permission string) (bool, logging.Info.Printf("Successfully called runc for '%s', output %s", containerID, stdoutStderr) } - logging.Info.Printf("Permission '%s', granted for Container '%s' via runc", containerID, permission) + logging.Info.Printf("Permission '%s', granted for Container '%s' via runc", permission, containerID) return true, nil } else { // Make sure path is relative to cgroupFSDockerDevices @@ -98,7 +98,7 @@ func (d cgroup) AddDevicesAllowed(containerID string, permission string) (bool, return false, dbus.MakeFailedError(fmt.Errorf("Can't write CGroup permission '%s': %s", permission, err)) } - logging.Info.Printf("Permission '%s', granted for Container '%s' via CGroup devices.allow", containerID, permission) + logging.Info.Printf("Permission '%s', granted for Container '%s' via CGroup devices.allow", permission, containerID) return true, nil } }