[LTP] [PATCH] cgroup: Handle trailing new line in cgroup.controllers

Richard Palethorpe rpalethorpe@suse.com
Wed Oct 25 13:05:33 CEST 2023


The last item in cgroup.controllers (misc in my case) contained a new
line character which caused the controller search to fail.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---

This stops cgroup_regression_test.sh from failing on
Tumbleweed. However there are other issues with that test which are
not addressed by this patch.

 lib/tst_cgroup.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 5240aadaa..d70b5431d 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -433,9 +433,20 @@ __attribute__ ((nonnull, warn_unused_result))
 static struct cgroup_ctrl *cgroup_find_ctrl(const char *const ctrl_name)
 {
 	struct cgroup_ctrl *ctrl;
+	int l = 0;
+
+	while (ctrl_name[l] >= 'a' && ctrl_name[l] <= 'z')
+		l++;
+
+	switch (ctrl_name[l]) {
+	case '\n': break;
+	case '\0': break;
+	default:
+		tst_brk(TBROK, "Unexpected char in %s: %c", ctrl_name, ctrl_name[l]);
+	}
 
 	for_each_ctrl(ctrl) {
-		if (!strcmp(ctrl_name, ctrl->ctrl_name))
+		if (!strncmp(ctrl_name, ctrl->ctrl_name, l))
 			return ctrl;
 	}
 
-- 
2.40.1



More information about the ltp mailing list