diff mbox series

[v6,1/5] Add SAFE_SYMLINKAT macro

Message ID 20240802-fchmodat2-v6-1-dcb0293979b3@suse.com
State Accepted
Headers show
Series Add fchmodat2 testing suite | expand

Commit Message

Andrea Cervesato Aug. 2, 2024, 10:59 a.m. UTC
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(+)

Comments

Petr Vorel Aug. 2, 2024, 11:31 a.m. UTC | #1
Hi Andrea,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr
Andrea Cervesato Aug. 2, 2024, 12:20 p.m. UTC | #2
On 8/2/24 13:31, Petr Vorel wrote:
> Hi Andrea,
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
> Kind regards,
> Petr

Pushed!

Thanks,
Andrea
diff mbox series

Patch

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;
+}
+