Skip to content

Commit b35a8f1

Browse files
Refine nb_matching_cgroup_mounts computation through use of grep
As suggested in #599 (review) Verified manually and through https://stackoverflow.com/a/42399738 Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 50cc4d1 commit b35a8f1

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

stemcell_builder/stages/bosh_monit/assets/monit-access-helper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ permit_monit_access() {
3030
# Create a sub-cgroup under the current process's cgroup and move into it.
3131
# The iptables rules match on this cgroup path.
3232
cgroup_mount="$(awk '$1 == "cgroup2" && $3 == "cgroup2" { print $2 }' /proc/self/mounts)"
33-
nb_matching_cgroup_mounts=$(echo "$cgroup_mount" | wc -l)
33+
nb_matching_cgroup_mounts=$(echo "$cgroup_mount" | grep -c '^.')
3434
current_cgroup="$(grep '^0::' /proc/self/cgroup | cut -d: -f3)"
3535
if [ -z "${cgroup_mount}" ] || [ "${nb_matching_cgroup_mounts}" -ne 1 ] || [ -z "${current_cgroup}" ]; then
3636
echo "permit_monit_access: unable to resolve cgroup v2 mount or path. current_cgroup=${current_cgroup} cgroup_mount=${cgroup_mount}" >&2

0 commit comments

Comments
 (0)