[LTP] [PATCH v6 1/5] Add SAFE_SYMLINKAT macro

Andrea Cervesato andrea.cervesato@suse.de
Fri Aug 2 12:59:04 CEST 2024


From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tst_safe_macros.h |  6 ++++++
 lib/tst_safe_macros.c     | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 92b9bc119..4df23e602 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -509,4 +509,10 @@ int safe_prctl(const char *file, const int lineno,
 #define SAFE_PRCTL(option, arg2, arg3, arg4, arg5) \
 	safe_prctl(__FILE__, __LINE__, (option), (arg2), (arg3), (arg4), (arg5))
 
+int safe_symlinkat(const char *file, const int lineno,
+	const char *oldpath, const int newdirfd, const char *newpath);
+
+#define SAFE_SYMLINKAT(oldpath, newdirfd, newpath) \
+	safe_symlinkat(__FILE__, __LINE__, (oldpath), (newdirfd), (newpath))
+
 #endif /* TST_SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index 1bc5c92f5..868ebc08e 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -731,3 +731,23 @@ int safe_prctl(const char *file, const int lineno,
 
 	return rval;
 }
+
+int safe_symlinkat(const char *file, const int lineno,
+                 const char *oldpath, const int newdirfd, const char *newpath)
+{
+	int rval;
+
+	rval = symlinkat(oldpath, newdirfd, newpath);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"symlinkat(%s,%d,%s) failed", oldpath, newdirfd, newpath);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid symlinkat(%s,%d,%s) return value %d", oldpath,
+			newdirfd, newpath, rval);
+	}
+
+	return rval;
+}
+

-- 
2.43.0



More information about the ltp mailing list