From 2a4df0c08245fd837f798fb3f8a0cee7ef5ecdb3 Mon Sep 17 00:00:00 2001
From: Ismael Luceno <ismael@sourcemage.org>
Date: Sat, 15 Aug 2026 04:00:00 +0100
Subject: [PATCH 3/5] Explain cgroup setup failures

Upstream-Status: Submitted [https://github.com/89luca89/lilipod/pull/50]
Signed-off-by: Ismael Luceno <ismael@sourcemage.org>
---
 pkg/containerutils/rootfs_utils.go | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/pkg/containerutils/rootfs_utils.go b/pkg/containerutils/rootfs_utils.go
index b21926d68002..137f42779306 100644
--- a/pkg/containerutils/rootfs_utils.go
+++ b/pkg/containerutils/rootfs_utils.go
@@ -84,19 +84,26 @@ func setupCgroupfs(conf utils.Config) error {
 
 	// move our process to a dedicated scope, so that eventual init systems
 	// won't encour problems with unknown PIDs
-	err = os.MkdirAll("/sys/fs/cgroup/container-"+conf.Names+".scope", 0o755)
+	scope := "/sys/fs/cgroup/container-" + conf.Names + ".scope"
+	err = os.MkdirAll(scope, 0o755)
 	if err != nil {
-		return err
+		return fmt.Errorf("cannot create cgroup %s: %w", scope, err)
 	}
 
-	file, err := os.Create("/sys/fs/cgroup/container-" + conf.Names + ".scope/cgroup.procs")
+	file, err := os.Create(scope + "/cgroup.procs")
 	if err != nil {
-		return err
+		return fmt.Errorf("cannot open %s/cgroup.procs: %w", scope, err)
 	}
 
+	defer file.Close()
+
 	_, err = fmt.Fprint(file, 0)
+	if err != nil {
+		return fmt.Errorf("cannot move the container process into %s: %w\n",
+			scope, err)
+	}
 
-	return err
+	return nil
 }
 
 // we need to setup the /dev/pts mountpoint, by mounting a new devpts filesystem
