[LTP] [PATCH v3 1/3] Add SAFE_ACCESS macro
Dai Shili
daisl.fnst@fujitsu.com
Fri Mar 18 19:55:45 CET 2022
Signed-off-by: Dai Shili <daisl.fnst@fujitsu.com>
---
include/tst_safe_macros.h | 5 +++++
lib/tst_safe_macros.c | 19 +++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 9a543e4..81c4b08 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -24,6 +24,11 @@
#include "safe_macros_fn.h"
#include "tst_cmd.h"
+int safe_access(const char *filename, const int lineno, const char *pathname,
+ int mode);
+#define SAFE_ACCESS(path, mode) \
+ safe_access(__FILE__, __LINE__, (path), (mode))
+
#define SAFE_BASENAME(path) \
safe_basename(__FILE__, __LINE__, NULL, (path))
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index a9f6aeb..c4cdc87 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -20,6 +20,25 @@
#include "lapi/personality.h"
#include "lapi/pidfd.h"
+int safe_access(const char *file, const int lineno,
+ const char *pathname, int mode)
+{
+ int rval;
+
+ rval = access(pathname, mode);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "access(%s,%d) failed", pathname, mode);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid access(%s,%d) return value %d", pathname,
+ mode, rval);
+ }
+
+ return rval;
+}
+
int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)
{
int rval;
--
1.8.3.1
More information about the ltp
mailing list