[LTP] [PATCH v4 1/3] tst_safe_file_at: Add SAFE_FCHOWNAT macro
Yang Xu
xuyang2018.jy@fujitsu.com
Fri Aug 26 05:59:23 CEST 2022
Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/tst_safe_file_at.h | 9 +++++++++
lib/tst_safe_file_at.c | 20 ++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/tst_safe_file_at.h b/include/tst_safe_file_at.h
index 8df34227f..e253198e6 100644
--- a/include/tst_safe_file_at.h
+++ b/include/tst_safe_file_at.h
@@ -25,6 +25,10 @@
#define SAFE_UNLINKAT(dirfd, path, flags) \
safe_unlinkat(__FILE__, __LINE__, (dirfd), (path), (flags))
+#define SAFE_FCHOWNAT(dirfd, path, owner, group, flags) \
+ safe_fchownat(__FILE__, __LINE__, \
+ (dirfd), (path), (owner), (group), (flags))
+
const char *tst_decode_fd(const int fd)
__attribute__((warn_unused_result));
@@ -58,4 +62,9 @@ int safe_unlinkat(const char *const file, const int lineno,
const int dirfd, const char *const path, const int flags)
__attribute__ ((nonnull));
+int safe_fchownat(const char *const file, const int lineno,
+ const int dirfd, const char *const path, uid_t owner,
+ gid_t group, int flags)
+ __attribute__ ((nonnull));
+
#endif
diff --git a/lib/tst_safe_file_at.c b/lib/tst_safe_file_at.c
index ca8ef2f68..6370a68e5 100644
--- a/lib/tst_safe_file_at.c
+++ b/lib/tst_safe_file_at.c
@@ -195,3 +195,23 @@ int safe_unlinkat(const char *const file, const int lineno,
return rval;
}
+
+int safe_fchownat(const char *const file, const int lineno,
+ const int dirfd, const char *const path, uid_t owner, gid_t group, int flags)
+{
+ int rval;
+
+ rval = fchownat(dirfd, path, owner, group, flags);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "fchownat(%d<%s>, '%s', %d, %d, %d) failed", dirfd,
+ tst_decode_fd(dirfd), path, owner, group, flags);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid fchownat(%d<%s>, '%s', %d, %d, %d) return value %d",
+ dirfd, tst_decode_fd(dirfd), path, owner, group, flags, rval);
+ }
+
+ return rval;
+}
--
2.27.0
More information about the ltp
mailing list