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

Cyril Hrubis chrubis@suse.cz
Thu Jul 9 10:53:51 CEST 2026


Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 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



More information about the ltp mailing list