From c97618944439c4d71ec4a492dbdf0c83d47c75a3 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Tue, 26 Apr 2016 15:28:16 +0100 Subject: [PATCH] cgroups: fix get attributes for controller noprefix mounted CGroups controller can be mounted by specifying a "noprefix" option, in which case attribute names are named as: / instead of the (more recent) naming schema using: /. For example, Android uses the old format for backward compatibility with user-space. Thus, it's possible in general to work on a target system where some controller are mounted "noprefix" while others not. This patchset adds a set of updates which allows to use the proper attributes naming schema based on how the controller has been mounted. This patch provides a more generic implementation of the get attributes shutils which is working also for noprefix mounted controllers. Signed-off-by: Patrick Bellasi --- devlib/bin/scripts/shutils.in | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/devlib/bin/scripts/shutils.in b/devlib/bin/scripts/shutils.in index f69bce3..ef4d3bd 100755 --- a/devlib/bin/scripts/shutils.in +++ b/devlib/bin/scripts/shutils.in @@ -62,12 +62,26 @@ ftrace_get_function_stats() { ################################################################################ cgroups_get_attributes() { - [[ $# -eq 2 ]] || exit -1 + test $# -eq 2 || exit -1 CGROUP="$1" CONTROLLER="$2" - $GREP '' $CGROUP/* | \ - $GREP "$CONTROLLER\." | \ - $SED -e "s|$CONTROLLER\.||" -e "s|$CGROUP/||" + # Check if controller is mounted with "noprefix" option, which is quite + # common on Android for backward compatibility + ls $CGROUP/$CONTROLLER\.* 2>&1 >/dev/null + if [ $? -eq 0 ]; then + # no "noprefix" option, attributes format is: + # mnt_point/controller.attribute_name + $GREP '' $CGROUP/* | \ + $GREP "$CONTROLLER\." | \ + $SED -e "s|$CONTROLLER\.||" -e "s|$CGROUP/||" + else + # "noprefix" option, attribute format is: + # mnt_point/attribute_name + $GREP '' $(\ + $FIND $CGROUP -type f -maxdepth 1 | + $GREP -v -e ".*tasks" -e ".*cgroup\..*") | \ + $SED "s|$CGROUP/||" + fi } cgroups_run_into() {