diff mbox series

[v4,2/3] tst_safe_file_at: Add SAFE_FSTATAT macro

Message ID 1663143142-2283-2-git-send-email-xuyang2018.jy@fujitsu.com
State Superseded
Headers show
Series [v4,1/3] syscalls/creat09: Add umask test condition | expand

Commit Message

Yang Xu Sept. 14, 2022, 8:12 a.m. UTC
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/tst_safe_file_at.h |  7 +++++++
 lib/tst_safe_file_at.c     | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)

Comments

Cyril Hrubis Sept. 14, 2022, 11:30 a.m. UTC | #1
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
diff mbox series

Patch

diff --git a/include/tst_safe_file_at.h b/include/tst_safe_file_at.h
index e253198e6..082a5acd9 100644
--- a/include/tst_safe_file_at.h
+++ b/include/tst_safe_file_at.h
@@ -29,6 +29,9 @@ 
 	safe_fchownat(__FILE__, __LINE__,				\
 			(dirfd), (path), (owner), (group), (flags))
 
+#define SAFE_FSTATAT(dirfd, path, statbuf, flags)			\
+	safe_fstatat(__FILE__, __LINE__, (dirfd), (path), (statbuf), (flags))
+
 const char *tst_decode_fd(const int fd)
 			  __attribute__((warn_unused_result));
 
@@ -67,4 +70,8 @@  int safe_fchownat(const char *const file, const int lineno,
 		  gid_t group, int flags)
 		  __attribute__ ((nonnull));
 
+int safe_fstatat(const char *const file, const int lineno,
+		 const int dirfd, const char *const path, struct stat *statbuf,
+		 int flags)
+		 __attribute__ ((nonnull));
 #endif
diff --git a/lib/tst_safe_file_at.c b/lib/tst_safe_file_at.c
index 6370a68e5..f530dc349 100644
--- a/lib/tst_safe_file_at.c
+++ b/lib/tst_safe_file_at.c
@@ -215,3 +215,23 @@  int safe_fchownat(const char *const file, const int lineno,
 
 	return rval;
 }
+
+int safe_fstatat(const char *const file, const int lineno,
+		 const int dirfd, const char *const path, struct stat *statbuf, int flags)
+{
+	int rval;
+
+	rval = fstatat(dirfd, path, statbuf, flags);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "fstatat(%d<%s>, '%s', %p, %d) failed", dirfd,
+			 tst_decode_fd(dirfd), path, statbuf, flags);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "Invalid fstatat(%d<%s>, '%s', %p, %d) return value %d",
+			 dirfd, tst_decode_fd(dirfd), path, statbuf, flags, rval);
+	}
+
+	return rval;
+}