diff mbox series

[v5,3/5] Add fchmodat2 fallback definition

Message ID 20240802-fchmodat2-v5-3-bff2ec1a4f06@suse.com
State Accepted
Headers show
Series Add fchmodat2 testing suite | expand

Commit Message

Andrea Cervesato Aug. 2, 2024, 8:23 a.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

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

Comments

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


>  include/lapi/stat.h | 16 ++++++++++++++++
What is the reason this to be added to include/lapi/stat.h?

It's not a general function? (otherwise tst_safe_macros.c would be more
appropriate).

And because one day it will be defined in <sys/stat.h>?

Probably ok due both reasons, but I'm just curious, also because static inline
brought various problems in the past.


>  1 file changed, 16 insertions(+)

> diff --git a/include/lapi/stat.h b/include/lapi/stat.h
> index 3606c9eb0..8e38ecfef 100644
> --- a/include/lapi/stat.h
> +++ b/include/lapi/stat.h
> @@ -229,4 +229,20 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
>  # define STATX_ATTR_VERITY	0x00100000
>  #endif

> +#define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
> +	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
> +
> +static inline int safe_fchmodat2(const char *file, const int lineno,
> +		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_(file, lineno, TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
> +			__func__, dfd, filename, mode, flags);
> +
> +	return ret;

The code itself is obviously correct.

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

Kind regards,
Petr

> +}
> +
>  #endif /* LAPI_STAT_H__ */
Andrea Cervesato Aug. 2, 2024, 10:38 a.m. UTC | #2
Hi,

On 8/2/24 11:55, Petr Vorel wrote:
> Hi Andrea,
>
>
>>   include/lapi/stat.h | 16 ++++++++++++++++
> What is the reason this to be added to include/lapi/stat.h?
>
> It's not a general function? (otherwise tst_safe_macros.c would be more
> appropriate).
>
> And because one day it will be defined in <sys/stat.h>?
>
> Probably ok due both reasons, but I'm just curious, also because static inline
> brought various problems in the past.
>
I was asked by Cyril to use proper headers instead of safe macros 
headers, which contain anything.
>>   1 file changed, 16 insertions(+)
>> diff --git a/include/lapi/stat.h b/include/lapi/stat.h
>> index 3606c9eb0..8e38ecfef 100644
>> --- a/include/lapi/stat.h
>> +++ b/include/lapi/stat.h
>> @@ -229,4 +229,20 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
>>   # define STATX_ATTR_VERITY	0x00100000
>>   #endif
>> +#define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
>> +	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
>> +
>> +static inline int safe_fchmodat2(const char *file, const int lineno,
>> +		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_(file, lineno, TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
>> +			__func__, dfd, filename, mode, flags);
>> +
>> +	return ret;
> The code itself is obviously correct.
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
> Kind regards,
> Petr
>
>> +}
>> +
>>   #endif /* LAPI_STAT_H__ */

Andrea
Petr Vorel Aug. 2, 2024, 10:57 a.m. UTC | #3
Hi Andrea,

> Hi,

> On 8/2/24 11:55, Petr Vorel wrote:
> > Hi Andrea,


> > >   include/lapi/stat.h | 16 ++++++++++++++++
> > What is the reason this to be added to include/lapi/stat.h?

> > It's not a general function? (otherwise tst_safe_macros.c would be more
> > appropriate).

> > And because one day it will be defined in <sys/stat.h>?

> > Probably ok due both reasons, but I'm just curious, also because static inline
> > brought various problems in the past.

> I was asked by Cyril to use proper headers instead of safe macros headers,
> which contain anything.

Thanks for info, I'm sorry for the noise.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index 3606c9eb0..8e38ecfef 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -229,4 +229,20 @@  static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_ATTR_VERITY	0x00100000
 #endif
 
+#define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
+	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
+
+static inline int safe_fchmodat2(const char *file, const int lineno,
+		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_(file, lineno, TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
+			__func__, dfd, filename, mode, flags);
+
+	return ret;
+}
+
 #endif /* LAPI_STAT_H__ */