[LTP] [PATCH v2 1/2] Add SAFE_KEYCTL macro
Andrea Cervesato
andrea.cervesato@suse.de
Wed Aug 21 14:04:25 CEST 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/keyctl.h | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/include/lapi/keyctl.h b/include/lapi/keyctl.h
index 3be782494..e11f62282 100644
--- a/include/lapi/keyctl.h
+++ b/include/lapi/keyctl.h
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ * Ccmdyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
*/
#ifndef LAPI_KEYCTL_H__
@@ -179,4 +179,28 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {
# define KEY_OTH_ALL 0x0000003f
#endif /* !KEY_POS_VIEW */
+static inline long safe_keyctl(const char *file, const int lineno,
+ int cmd, unsigned long arg2, unsigned long arg3,
+ unsigned long arg4, unsigned long arg5)
+{
+ long rval;
+
+ rval = keyctl(cmd, arg2, arg3, arg4, arg5);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "keyctl(%d, %lu, %lu, %lu, %lu)",
+ cmd, arg2, arg3, arg4, arg5);
+ } else if (rval < 0) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid keyctl(%d, %lu, %lu, %lu, %lu) "
+ "return value %ld",
+ cmd, arg2, arg3, arg4, arg5, rval);
+ }
+
+ return rval;
+}
+#define SAFE_KEYCTL(cmd, arg2, arg3, arg4, arg5) \
+ safe_keyctl(__FILE__, __LINE__, \
+ (cmd), (arg2), (arg3), (arg4), (arg5))
+
#endif /* LAPI_KEYCTL_H__ */
--
2.43.0
More information about the ltp
mailing list