[LTP] [PATCH v3 1/3] Add more mqueue safe macros

Andrea Cervesato andrea.cervesato@suse.com
Tue Aug 16 13:31:40 CEST 2022


Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tst_safe_posix_ipc.h | 73 ++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/include/tst_safe_posix_ipc.h b/include/tst_safe_posix_ipc.h
index b60c12c9e..78ce660b5 100644
--- a/include/tst_safe_posix_ipc.h
+++ b/include/tst_safe_posix_ipc.h
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2017-2019 Petr Vorel pvorel@suse.cz
+ * Copyright (C) 2022 Andrea Cervesato andrea.cervesato@suse.com
  */
 
 #ifndef TST_SAFE_POSIX_IPC_H__
@@ -12,6 +13,18 @@
 #define SAFE_MQ_OPEN(pathname, oflags, ...) \
 	safe_mq_open(__FILE__, __LINE__, (pathname), (oflags), ##__VA_ARGS__)
 
+#define SAFE_MQ_NOTIFY(mqdes, sevp) \
+	safe_mq_notify(__FILE__, __LINE__, (mqdes), (sevp))
+
+#define SAFE_MQ_SEND(mqdes, msg_ptr, msg_len, msg_prio) \
+	safe_mq_send(__FILE__, __LINE__, (mqdes), (msg_ptr), (msg_len), (msg_prio))
+
+#define SAFE_MQ_CLOSE(mqdes) \
+	safe_mq_close(__FILE__, __LINE__, (mqdes))
+
+#define SAFE_MQ_UNLINK(name) \
+	safe_mq_unlink(__FILE__, __LINE__, (name))
+
 static inline int safe_mq_open(const char *file, const int lineno,
 			       const char *pathname, int oflags, ...)
 {
@@ -46,4 +59,64 @@ static inline int safe_mq_open(const char *file, const int lineno,
 	return rval;
 }
 
+static int safe_mq_notify(const char *file, const int lineno,
+			  mqd_t mqdes, const struct sigevent *sevp)
+{
+	int rval;
+
+	rval = mq_notify(mqdes, sevp);
+
+	if (rval == -1)
+		tst_brk_(file, lineno, TBROK | TERRNO, "mq_notify() failed");
+
+	return rval;
+}
+
+static int safe_mq_send(const char *file, const int lineno,
+			mqd_t mqdes, const char *msg_ptr,
+			size_t msg_len, unsigned int msg_prio)
+{
+	int rval;
+
+	rval = mq_send(mqdes, msg_ptr, msg_len, msg_prio);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO, 
+			"mq_send(%d,%s,%lu,%d) failed", mqdes, msg_ptr,
+			msg_len, msg_prio);
+	}
+
+	return rval;
+}
+
+static int safe_mq_close(const char *file, const int lineno,
+			  mqd_t mqdes)
+{
+	int rval;
+
+	rval = mq_close(mqdes);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"mq_close(%d) failed", mqdes);
+	}
+
+	return rval;
+}
+
+static int safe_mq_unlink(const char *file, const int lineno,
+			  const char *name)
+{
+	int rval;
+
+	rval = mq_unlink(name);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"mq_unlink(%s) failed", name);
+	}
+
+	return rval;
+}
+
 #endif /* TST_SAFE_POSIX_IPC_H__ */
-- 
2.35.3



More information about the ltp mailing list