[PATCH v3 7/9] SAFE_MACROS: Add SAFE_POLL()

Cyril Hrubis <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
Signed-off-by: Cyril Hrubis <[email protected]>
---
 include/tst_safe_macros.h |  6 ++++++
 lib/tst_safe_macros.c     | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index c73c1acb1..91a130a48 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <grp.h>
+#include <poll.h>
 
 #include "safe_stdio_fn.h"
 #include "safe_macros_fn.h"
@@ -517,4 +518,9 @@ int safe_statvfs(const char *file, const int lineno,
 #define SAFE_STATVFS(path, buf) \
 	safe_statvfs(__FILE__, __LINE__, (path), (buf))
 
+int safe_poll(const char *const file, const int lineno, struct pollfd *fds,
+		nfds_t nfds, int timeout);
+#define SAFE_POLL(fds, nfds, timeout) \
+	safe_poll(__FILE__, __LINE__, (fds), (nfds), (timeout))
+
 #endif /* TST_SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index cdc8c7dd3..f17f911ef 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -829,3 +829,21 @@ int safe_statvfs(const char *file, const int lineno,
 
 	return rval;
 }
+
+int safe_poll(const char *const file, const int lineno, struct pollfd *fds,
+		nfds_t nfds, int timeout)
+{
+	int rval;
+
+	rval = poll(fds, nfds, timeout);
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"poll(%p, %li, %i) failed", fds, (long)nfds, timeout);
+	} else if (rval < -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid poll(%p, %li, %i) return value %i",
+			fds, (long)nfds, timeout, rval);
+	}
+
+	return rval;
+}
-- 
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.