Skip to content

Commit 3bb9deb

Browse files
committed
ci: ensure the cgroup parent always exists for rootless
On some systems (e.g., AlmaLinux 8), systemd automatically removes cgroup paths when they become empty (i.e., contain no processes). To prevent this, we spawn a dummy process to pin the cgroup in place. Fix: #5003 Signed-off-by: lifubang <[email protected]>
1 parent 090078f commit 3bb9deb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/rootless.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,20 @@ function cleanup() {
9797
ALL_CGROUPS=($(cut -d: -f2 </proc/self/cgroup | sed -E '{s/^name=//;s/,/\n/;/^$/D}'))
9898
CGROUP_MOUNT="/sys/fs/cgroup"
9999
CGROUP_PATH="/runc-cgroups-integration-test"
100+
CGROUP_PIN_PID=-1
100101

101102
function enable_cgroup() {
103+
# On some systems (e.g., AlmaLinux 8), systemd automatically removes cgroup paths
104+
# when they become empty (i.e., contain no processes). To prevent this, we spawn
105+
# a dummy process to pin the cgroup in place.
106+
# See: https://github.com/opencontainers/runc/issues/5003
107+
sleep inf &
108+
CGROUP_PIN_PID=$!
102109
# Set up cgroups for use in rootless containers.
103110
for cg in "${ALL_CGROUPS[@]}"; do
104111
mkdir -p "$CGROUP_MOUNT/$cg$CGROUP_PATH"
112+
# TODO: Consider retrying on "No space left on device" errors.
113+
echo "$CGROUP_PIN_PID" >"$CGROUP_MOUNT/$cg$CGROUP_PATH/cgroup.procs" || true
105114
# We only need to allow write access to {cgroup.procs,tasks} and the
106115
# directory. Rather than changing the owner entirely, we just change
107116
# the group and then allow write access to the group (in order to
@@ -141,6 +150,11 @@ function enable_cgroup() {
141150
}
142151

143152
function disable_cgroup() {
153+
if [ $CGROUP_PIN_PID -ne -1 ]; then
154+
kill -9 "$CGROUP_PIN_PID" || true
155+
wait "$CGROUP_PIN_PID" 2>/dev/null || true
156+
CGROUP_PIN_PID=-1
157+
fi
144158
# Remove cgroups used in rootless containers.
145159
for cg in "${ALL_CGROUPS[@]}"; do
146160
[ -d "$CGROUP_MOUNT/$cg$CGROUP_PATH" ] && rmdir "$CGROUP_MOUNT/$cg$CGROUP_PATH"

0 commit comments

Comments
 (0)