[LTP] [PATCH v3 01/11] Add SAFE_STATX macro
Andrea Cervesato
andrea.cervesato@suse.de
Thu May 16 14:29:09 CEST 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/tst_safe_macros.h | 7 +++++++
lib/tst_safe_macros.c | 22 ++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 8de8ef106..43ff50a33 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -503,4 +503,11 @@ int safe_sscanf(const char *file, const int lineno, const char *restrict buffer,
#define SAFE_SSCANF(buffer, format, ...) \
safe_sscanf(__FILE__, __LINE__, (buffer), (format), ##__VA_ARGS__)
+struct statx;
+int safe_statx(const char *file, const int lineno,
+ int dirfd, const char *pathname, int flags, unsigned int mask,
+ struct statx *buf);
+#define SAFE_STATX(dirfd, pathname, flags, mask, buf) \
+ safe_statx(__FILE__, __LINE__, (dirfd), (pathname), (flags), (mask), (buf))
+
#endif /* TST_SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index 39b8cc924..f50a7bcc2 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -20,6 +20,7 @@
#include "tst_safe_macros.h"
#include "lapi/personality.h"
#include "lapi/pidfd.h"
+#include "lapi/stat.h"
int safe_access(const char *file, const int lineno,
const char *pathname, int mode)
@@ -710,3 +711,24 @@ int safe_mprotect(const char *file, const int lineno,
return rval;
}
+
+int safe_statx(const char *file, const int lineno,
+ int dirfd, const char *pathname, int flags, unsigned int mask,
+ struct statx *buf)
+{
+ int rval;
+
+ rval = statx(dirfd, pathname, flags, mask, buf);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "statx(%d,%s,%d,%u,%p) failed", dirfd, pathname, flags, mask, buf);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid statx(%d,%s,%d,%u,%p) return value %d",
+ dirfd, pathname, flags, mask, buf,
+ rval);
+ }
+
+ return rval;
+}
--
2.35.3
More information about the ltp
mailing list