|
4 | 4 | import os |
5 | 5 | import functools |
6 | 6 | import subprocess |
| 7 | +from pathlib import Path |
7 | 8 | from DIRAC import S_OK, S_ERROR, gLogger |
8 | 9 | from DIRAC.Core.Utilities.DIRACSingleton import DIRACSingleton |
9 | 10 | from DIRAC.Core.Utilities import Subprocess |
@@ -102,11 +103,29 @@ def filt(line): |
102 | 103 | return line[4:] |
103 | 104 | return False |
104 | 105 |
|
105 | | - if not (root_path := self._detect_root()): |
| 106 | + if not (root_name := self._detect_root()): |
106 | 107 | raise RuntimeError("Failed to find cgroup mount point") |
107 | 108 | if not (cur_group := self._filter_file(self.FILE_CUR_CGROUP, filt)): |
108 | 109 | raise RuntimeError("Failed to find current cgroup") |
109 | | - self._cgroup_path = os.path.join(root_path, cur_group) |
| 110 | + root_path = Path(root_name) |
| 111 | + search_path = root_path / cur_group |
| 112 | + # Work up from the search path until we find a writable directory |
| 113 | + num = 0 |
| 114 | + while search_path.is_relative_to(root_path): |
| 115 | + num += 1 |
| 116 | + if num > 10: |
| 117 | + # We've tried 10 levels of tree! There might be an oddity here |
| 118 | + # where we're stuck in a loop (perhaps we somehow got all the |
| 119 | + # way up to "/" and are just looping on that?) |
| 120 | + raise RuntimeError("Writeable cgroup search exceeded limit") |
| 121 | + if os.access(search_path, os.W_OK): |
| 122 | + # We found an entry in the tree that we can write to |
| 123 | + self._cgroup_path = str(search_path) |
| 124 | + return |
| 125 | + search_path = search_path.parent |
| 126 | + # We've now left the cgroup mount point and didn't find a writeable dir |
| 127 | + # There probably isn't any delegation enabled |
| 128 | + raise RuntimeError("Failed to find a writeable cgroup") |
110 | 129 |
|
111 | 130 | def _create_group(self, group_name, isolate_oom=True): |
112 | 131 | """Creates a new group. |
|
0 commit comments