[LTP] [PATCH 4/5] SAFE_MACROS: Add SAFE_PRCTL()

Guangwen Feng fenggw-fnst@cn.fujitsu.com
Wed Nov 30 13:12:34 CET 2016


Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 include/tst_safe_macros.h |  4 ++++
 lib/safe_macros.c         | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 2566079..bd60b40 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -480,4 +480,8 @@ int safe_system(const char *file, const int lineno, const char *cmd);
 #define SAFE_SYSTEM(cmd) \
 	safe_system(__FILE__, __LINE__, (cmd))
 
+int safe_prctl(const char *file, const int lineno, int opt, ...);
+#define SAFE_PRCTL(opt, ...) \
+	safe_prctl(__FILE__, __LINE__, (opt), ##__VA_ARGS__)
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 1c89b8c..c8c5383 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -807,3 +807,23 @@ int safe_system(const char *file, const int lineno, const char *cmd)
 
 	return rval;
 }
+
+int safe_prctl(const char *file, const int lineno, int opt, ...)
+{
+	va_list ap;
+	int rval;
+	unsigned long arg;
+
+	va_start(ap, opt);
+	arg = va_arg(ap, unsigned long);
+	va_end(ap);
+
+	rval = prctl(opt, arg);
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, NULL,
+			 "%s:%d prctl(%i, %lu) failed",
+			 file, lineno, opt, arg);
+	}
+
+	return rval;
+}
-- 
1.8.4.2





More information about the ltp mailing list