diff mbox series

[v3,3/5] Add fchmodat2 fallback definition

Message ID 20240724-fchmodat2-v3-3-1dc7cfc634b8@suse.com
State Accepted
Headers show
Series Add fchmodat2 testing suite | expand

Commit Message

Andrea Cervesato July 24, 2024, 9:45 a.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/lapi/stat.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Petr Vorel July 30, 2024, 9:14 a.m. UTC | #1
Hi Andrea,

...
> +static inline int fchmodat2(
> +	int dfd, const char *filename, mode_t mode, int flags)
IMHO more consistent is:
static inline int fchmodat2(int dfd, const char *filename, mode_t mode, int flags)

But more important, you need to have as first two params: const char *file,
const int lineno, e.g.:

#define SAFE_FCHMODAT2(path, mode) \
	safe_access(__FILE__, __LINE__, (filename), (mode), (flags))

static inline int fchmodat2(const char *file, const int lineno, int dfd, const
	    char *filename, mode_t mode, int flags)
{
...
#

This way instead of this:
../../../../include/lapi/stat.h:239: TBROK: fchmodat2(3,symlink,416,256) error: EOPNOTSUPP (95)
we get file and line of the test (common approach, see lib/tst_safe_macros.c
include/tst_safe_macros.h).

Kind regards,
Petr

> +{
> +	int ret;
> +
> +	ret = tst_syscall(__NR_fchmodat2, dfd, filename, mode, flags);
> +	if (ret == -1)
> +		tst_brk(TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
> +			__func__, dfd, filename, mode, flags);
> +
> +	return ret;
> +}
diff mbox series

Patch

diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index 3606c9eb0..5e289d3ca 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -229,4 +229,17 @@  static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_ATTR_VERITY	0x00100000
 #endif
 
+static inline int fchmodat2(
+	int dfd, const char *filename, mode_t mode, int flags)
+{
+	int ret;
+
+	ret = tst_syscall(__NR_fchmodat2, dfd, filename, mode, flags);
+	if (ret == -1)
+		tst_brk(TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
+			__func__, dfd, filename, mode, flags);
+
+	return ret;
+}
+
 #endif /* LAPI_STAT_H__ */