[LTP] [PATCH 1/4] API: cgroup: Add safe_cgroup_occursin

Richard Palethorpe rpalethorpe@suse.com
Tue Dec 14 10:06:45 CET 2021


Similar to cg_read_strstr from kselftests. The name was changed
because strstr from string.h returns a ptr and this does not.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 include/tst_cgroup.h |  8 ++++++++
 lib/tst_cgroup.c     | 12 ++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h
index 9e34321e4..632050e86 100644
--- a/include/tst_cgroup.h
+++ b/include/tst_cgroup.h
@@ -191,5 +191,13 @@ void safe_cgroup_scanf(const char *file, const int lineno,
 		       const char *fmt, ...)
 		       __attribute__ ((format (scanf, 5, 6), nonnull));
 
+#define SAFE_CGROUP_OCCURSIN(cg, file_name, needle)		\
+	safe_cgroup_occursin(__FILE__, __LINE__,		\
+			     (cg), (file_name), (needle))
+
+int safe_cgroup_occursin(const char *file, const int lineno,
+			 const struct tst_cgroup_group *const cg,
+			 const char *const file_name,
+			 const char *const needle);
 
 #endif /* TST_CGROUP_H */
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 61cc02fa7..f85dc4fdd 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -1153,3 +1153,15 @@ void safe_cgroup_scanf(const char *const file, const int lineno,
 		 "'%s': vsscanf('%s', '%s', ..): Less conversions than expected: %d != %d",
 		 file_name, buf, fmt, ret, conv_cnt);
 }
+
+int safe_cgroup_occursin(const char *const file, const int lineno,
+			 const struct tst_cgroup_group *const cg,
+			 const char *const file_name,
+			 const char *const needle)
+{
+	char buf[BUFSIZ];
+
+	safe_cgroup_read(file, lineno, cg, file_name, buf, sizeof(buf));
+
+	return !!strstr(buf, needle);
+}
-- 
2.34.0



More information about the ltp mailing list