Add SAFE_PIPE2() to LTP library

Signed-off-by: Francis Laniel <laniel_francis@privacyrequired.com>
Reviewed-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
Signed-off-by: Li Wang <liwang@redhat.com>
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index c76f57c..c39d876 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -88,6 +88,11 @@
 #define SAFE_PIPE(fildes) \
 	safe_pipe(__FILE__, __LINE__, NULL, (fildes))
 
+int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags);
+
+#define SAFE_PIPE2(fildes, flags) \
+	safe_pipe2(__FILE__, __LINE__, (fildes), (flags))
+
 #define SAFE_READ(len_strict, fildes, buf, nbyte) \
 	safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
 
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index 32aa984..dbdfcc5 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -233,3 +233,17 @@
 
 	return ret;
 }
+
+int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags)
+{
+	int ret;
+
+	ret = pipe2(fildes, flags);
+	if (ret == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"pipe2({%d,%d}) failed with flag(%d)",
+			fildes[0], fildes[1], flags);
+	}
+
+	return ret;
+}