From a9a722225fc283880f1584974c722eca272d6017 Mon Sep 17 00:00:00 2001 From: Simon Fayer Date: Tue, 9 Jun 2026 09:44:36 +0100 Subject: [PATCH] fix: Find writeable cgroup2 in tree --- src/DIRAC/Core/Utilities/CGroups2.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/DIRAC/Core/Utilities/CGroups2.py b/src/DIRAC/Core/Utilities/CGroups2.py index f7cb460f572..9f575ddfc1a 100644 --- a/src/DIRAC/Core/Utilities/CGroups2.py +++ b/src/DIRAC/Core/Utilities/CGroups2.py @@ -4,6 +4,7 @@ import os import functools import subprocess +from pathlib import Path from DIRAC import S_OK, S_ERROR, gLogger from DIRAC.Core.Utilities.DIRACSingleton import DIRACSingleton from DIRAC.Core.Utilities import Subprocess @@ -102,11 +103,29 @@ def filt(line): return line[4:] return False - if not (root_path := self._detect_root()): + if not (root_name := self._detect_root()): raise RuntimeError("Failed to find cgroup mount point") if not (cur_group := self._filter_file(self.FILE_CUR_CGROUP, filt)): raise RuntimeError("Failed to find current cgroup") - self._cgroup_path = os.path.join(root_path, cur_group) + root_path = Path(root_name) + search_path = root_path / cur_group + # Work up from the search path until we find a writable directory + num = 0 + while search_path.is_relative_to(root_path): + num += 1 + if num > 10: + # We've tried 10 levels of tree! There might be an oddity here + # where we're stuck in a loop (perhaps we somehow got all the + # way up to "/" and are just looping on that?) + raise RuntimeError("Writeable cgroup search exceeded limit") + if os.access(search_path, os.W_OK): + # We found an entry in the tree that we can write to + self._cgroup_path = str(search_path) + return + search_path = search_path.parent + # We've now left the cgroup mount point and didn't find a writeable dir + # There probably isn't any delegation enabled + raise RuntimeError("Failed to find a writeable cgroup") def _create_group(self, group_name, isolate_oom=True): """Creates a new group.