Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions sh/rc-cgroup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,26 @@ cgroup_add_service()
# it prevents unwanted inheriting of the user
# cgroups. But may lead to problems where that inheriting
# is needed.
local cgroup d openrc_cgroup
local attempts cgroup d openrc_cgroup
for d in /sys/fs/cgroup/* ; do
[ -w "${d}"/tasks ] && printf "%d" 0 > "${d}"/tasks
done

openrc_cgroup=/sys/fs/cgroup/openrc
if [ -d "$openrc_cgroup" ]; then
cgroup="$openrc_cgroup/$RC_SVCNAME"
mkdir -p "$cgroup"
[ -w "$cgroup/tasks" ] && printf "%d" 0 > "$cgroup/tasks"
attempts=0
# The asynchronous release agent may remove an empty cgroup
# between creating it and writing to tasks, so retry both.
while [ "$attempts" -lt 3 ]; do
mkdir -p "$cgroup" || return 0
if [ -w "$cgroup/tasks" ] &&
{ printf "%d" 0 > "$cgroup/tasks"; } 2> /dev/null
then
return 0
fi
attempts=$((attempts+1))
done
fi
}

Expand Down
Loading