Clean up cgroups v2 code

Remove the IFS manipulation and simplify the loop that processes the
settings.
This commit is contained in:
William Hubbs 2018-03-11 21:40:57 -05:00
parent 3e68013631
commit 61905bfcf5

View File

@ -184,18 +184,17 @@ cgroup2_set_limits()
cgroup_path="$(cgroup2_find_path)" cgroup_path="$(cgroup2_find_path)"
[ -d "${cgroup_path}" ] || return 0 [ -d "${cgroup_path}" ] || return 0
rc_cgroup_path="${cgroup_path}/${RC_SVCNAME}" rc_cgroup_path="${cgroup_path}/${RC_SVCNAME}"
local OIFS="$IFS"
IFS="
"
[ ! -d "${rc_cgroup_path}" ] && mkdir "${rc_cgroup_path}" [ ! -d "${rc_cgroup_path}" ] && mkdir "${rc_cgroup_path}"
printf "%d" 0 > "${rc_cgroup_path}/cgroup.procs" [ -f "${rc_cgroup_path}"/cgroup.procs ] &&
echo "${rc_cgroup_settings}" | while IFS="$OIFS" read -r key value; do printf 0 > "${rc_cgroup_path}"/cgroup.procs
[ -z "${key}" ] || [ -z "${value}" ] && continue [ -z "${rc_cgroup_settings}" ] && return 0
[ ! -e "${rc_cgroup_path}/${key}" ] && continue echo "${rc_cgroup_settings}" | while read -r key value; do
veinfo "${RC_SVCNAME}: cgroups: ${key} ${value}" [ -z "${key}" ] && continue
printf "%s" "${value}" > "${rc_cgroup_path}/${key}" [ -z "${value}" ] && continue
[ ! -f "${rc_cgroup_path}/${key}" ] && continue
veinfo "${RC_SVCNAME}: cgroups: setting ${key} to ${value}"
printf "%s\n" "${value}" > "${rc_cgroup_path}/${key}"
done done
IFS="$OIFS"
return 0 return 0
} }