[LTP] [PATCH 3/5] SAFE_MACROS: Add SAFE_SYSTEM()

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


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

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 9fa0e17..2566079 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -476,4 +476,8 @@ int safe_setpriority(const char *file, const int lineno, int which, id_t who,
 #define SAFE_SETPRIORITY(which, who, prio) \
 	safe_setpriority(__FILE__, __LINE__, (which), (who), (prio))
 
+int safe_system(const char *file, const int lineno, const char *cmd);
+#define SAFE_SYSTEM(cmd) \
+	safe_system(__FILE__, __LINE__, (cmd))
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index a109270..1c89b8c 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -793,3 +793,17 @@ int safe_setpriority(const char *file, const int lineno, int which, id_t who,
 
 	return rval;
 }
+
+int safe_system(const char *file, const int lineno, const char *cmd)
+{
+	int rval;
+
+	rval = system(cmd);
+	if (rval == -1 || !WIFEXITED(rval) || WEXITSTATUS(rval)) {
+		tst_brkm(TBROK | TERRNO, NULL,
+			 "%s:%d system(%s) failed",
+			 file, lineno, cmd);
+	}
+
+	return rval;
+}
-- 
1.8.4.2





More information about the ltp mailing list