syscalls/pidfd_open01.c: Add check for close-on-exec flag
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
pidfd_open(2) will set close-on-exec flag on the file descriptor as it manpage states, so check close-on-exec flag by fcntl(2).
BTW:
I tried to pass (long) TST_RET to fcntl() but triggered the following
compiler warning, so pass (int) pidfd instead.
------------------------------------------------------
In file included from pidfd_open01.c:9:pidfd_open01.c: In function ?run?:../../../../include/tst_test.h:76:41: warning: format ?%i? expects argument of type ?int?, but argument 5 has type ?long int? [-Wformat=]
76 | tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
| ^~~~~~~~~../../../../include/tst_safe_macros.h:224:5: note: in expansion of macro ?tst_brk?
224 | tst_brk(TBROK | TERRNO, \
| ^~~~~~~pidfd_open01.c:20:9: note: in expansion of macro ?SAFE_FCNTL?
20 | flag = SAFE_FCNTL(TST_RET, F_GETFD);
------------------------------------------------------
--- testcases/kernel/syscalls/pidfd_open/pidfd_open01.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/pidfd_open/pidfd_open01.c +8 -1
@@ -11,13 +11,20 @@static void run (void ) { -TEST (pidfd_open (getpid (),0 )); +int pidfd, flag; + +TEST (pidfd =pidfd_open (getpid (),0 ));if (TST_RET ==-1 )tst_brk (TFAIL |TTERRNO ,"pidfd_open(getpid(), 0) failed" ); + flag =SAFE_FCNTL (pidfd,F_GETFD ); +SAFE_CLOSE (TST_RET ); +if (!(flag &FD_CLOEXEC )) +tst_brk (TFAIL ,"pidfd_open(getpid(), 0) didn't set close-on-exec flag" ); +tst_res (TPASS ,"pidfd_open(getpid(), 0) passed" ); }
Signature · 1 line
2.21.0
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Hi Cyril, Petr
For the patch set, I and Viresh have the following doubts so do you have any suggestion about them?
1) I keep TEST() in pidfd_open01/pidfd_open03 for now but I think it is surplus because pidfd/fd and TERRNO are enough to check return value and errno.
I wonder if it is necessary to keep TEST()?
2) tst_syscall() is enough to check the support of pidfd_open() and I don't want to define check function as fsopen_supported_by_kernel() does.
Do you think so?
BTW:
I don't like the implementation of fsopen_supported_by_kernel():
a) syscall()/tst_syscall() is enough to check the support of pidfd_open(2) and 'tst_kvercmp(5, 2, 0)) < 0' will skip the check if a kernel on distribution is newer than v5.2 but drop the support of pidfd_open(2) on purpose.
b) tst_syscall() has checked ENOSYS error so we can simple fsopen_supported_by_kernel() by replacing syscall() with tst_syscalls().
Best Regards,
Xiao Yang
Quoted 51 lines · Xiao Yang
pidfd_open(2)will set close-on-exec flag on the file descriptor as it manpage states, so check close-on-exec flag by fcntl(2).BTW:
I tried to pass (long)TST_RETtofcntl()but triggered the following
compiler warning, so pass (int) pidfd instead.
------------------------------------------------------
In file included from pidfd_open01.c:9:pidfd_open01.c: In function ?run?:../../../../include/tst_test.h:76:41: warning: format ?%i? expects argument of type ?int?, but argument 5 has type ?long int? [-Wformat=]76 | tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\ | ^~~~~~~~~ ../../../../include/tst_safe_macros.h:224:5: note: in expansion of macro ?tst_brk? 224 | tst_brk(TBROK | TERRNO, \ | ^~~~~~~ pidfd_open01.c:20:9: note: in expansion of macro ?SAFE_FCNTL? 20 | flag = SAFE_FCNTL(TST_RET, F_GETFD);------------------------------------------------------
Signed-off-by Xiao Yang<[email protected]>Reviewed-by Viresh Kumar<[email protected]>--- testcases/kernel/syscalls/pidfd_open/pidfd_open01.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)testcases/kernel/syscalls/pidfd_open/pidfd_open01.c +8
-1@@ -11,13 +11,20 @@static void run (void ) { -TEST (pidfd_open (getpid (),0 )); +int pidfd, flag; + +TEST (pidfd =pidfd_open (getpid (),0 ));if (TST_RET ==-1 )tst_brk (TFAIL |TTERRNO ,"pidfd_open(getpid(), 0) failed" ); + flag =SAFE_FCNTL (pidfd,F_GETFD ); +SAFE_CLOSE (TST_RET ); +if (!(flag&FD_CLOEXEC )) +tst_brk (TFAIL ,"pidfd_open(getpid(), 0) didn't set close-on-exec flag" ); +tst_res (TPASS ,"pidfd_open(getpid(), 0) passed" ); }
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Hi Yang,
Quoted 6 lines
For the patch set, I and Viresh have the following doubts so do you have any suggestion about them?
1) I keepTEST()in pidfd_open01/pidfd_open03 for now but I think it is surplus because pidfd/fd and TERRNO are enough to check return value and errno.
I wonder if it is necessary to keepTEST()?
yes, I've noticed your discussion at v1, sorry I wasn't able to follow.
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Just to get context, We're talking about part of the changes between v1 and v2:
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c @@ -27,9 +27,11 @@ static void run(void)
exit(EXIT_SUCCESS);
}- fd = pidfd_open(pid, 0);
+ TEST(pidfd_open(pid, 0));
+
+ fd = TST_RET;
if (fd == -1)
- tst_brk(TFAIL | TERRNO, "pidfd_open() failed");
+ tst_brk(TFAIL | TTERRNO, "pidfd_open() failed");TST_CHECKPOINT_WAKE(0);
I haven't found Cyril's request to use TEST(). To be honest, not sure if it was meant to make sure that errno needs to be reset before (which TEST()) does. If not, using pidfd_open() directly would be ok for me.
Quoted 9 lines
2)
tst_syscall()is enough to check the support ofpidfd_open()and I don't want to define check function asfsopen_supported_by_kernel()does.
Do you think so?BTW:
I don't like the implementation offsopen_supported_by_kernel():
a) syscall()/tst_syscall() is enough to check the support ofpidfd_open(2)and 'tst_kvercmp(5, 2, 0)) < 0' will skip the check if
+1 for tst_syscall()
Quoted 2 lines
a kernel on distribution is newer than v5.2 but drop the support of
pidfd_open(2)on purpose.
"drop support of pidfd_open(2) on purpose": would anybody has a reason to do that?
Quoted 2 lines
b)
tst_syscall()has checked ENOSYS error so we can simplefsopen_supported_by_kernel()by replacingsyscall()withtst_syscalls().
Well, one of the benefits of fsopen_supported_by_kernel() was to reduce a bit of duplicity. Even if the implementation is like TEST and SAFE_CLOSE(), it's a fewer lines (+ function name as a self docs).
void fsopen_supported_by_kernel(void)
{
TEST(tst_syscall(__NR_fsopen, NULL, 0));
if (TST_RET != -1)
SAFE_CLOSE(TST_RET);
}For your change for pidfd_open03.c:
static void setup(void)
{
int pidfd = -1;
// Check if pidfd_open(2) is not supported
pidfd = tst_syscall(__NR_pidfd_open, getpid(), 0);
if (pidfd != -1)
SAFE_CLOSE(pidfd);
} static struct tst_test test = {
- .min_kver = "5.3",
+ .setup = setup,
How about to call the function pidfd_open_supported_by_kernel()? Than you can remove the comment (which BTW should use C style /* */). And IMHO you don't have to assign pidfd to -1.
Kind regards,
Petr
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Quoted 28 lines · Petr Vorel
Hi Yang,
Quoted 6 lines
For the patch set, I and Viresh have the following doubts so do you have any suggestion about them?
1) I keepTEST()in pidfd_open01/pidfd_open03 for now but I think it is surplus because pidfd/fd and TERRNO are enough to check return value and errno.
I wonder if it is necessary to keepTEST()?yes, I've noticed your discussion at v1, sorry I wasn't able to follow.
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Just to get context, We're talking about part of the changes between v1 and v2:+++
b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c(quoted diff) +4
-2@@ -27,9 +27,11 @@ static void run(void) exit(EXIT_SUCCESS); } - fd = pidfd_open(pid, 0); + TEST(pidfd_open(pid, 0)); + + fd = TST_RET; if (fd == -1) - tst_brk(TFAIL | TERRNO, "pidfd_open() failed"); + tst_brk(TFAIL | TTERRNO, "pidfd_open() failed"); TST_CHECKPOINT_WAKE(0);
Quoted 3 lines
I haven't found Cyril's request to use
TEST(). To be honest, not sure if it was meant to make sure that errno needs to be reset before (whichTEST()) does. If not, usingpidfd_open()directly would be ok for me.
Hi Petr,
Thanks a lot for your quick reply.
Resetting errno may not necessary because errno will be set again when fd == -1.
Quoted 11 lines
Quoted 11 lines
2)
tst_syscall()is enough to check the support ofpidfd_open()and I don't want to define check function asfsopen_supported_by_kernel()does.
Do you think so?BTW:
I don't like the implementation offsopen_supported_by_kernel():
a) syscall()/tst_syscall() is enough to check the support ofpidfd_open(2)and 'tst_kvercmp(5, 2, 0))< 0' will skip the check if
Quoted 6 lines
+1 for
tst_syscall()Quoted 2 lines
a kernel on distribution is newer than v5.2 but drop the support of
pidfd_open(2)on purpose."drop support of
pidfd_open(2)on purpose": would anybody has a reason to do that?
As my pervious mail said, It is just a possible situation? for example:
Upstream kernel introduces btrfs filesystem long long ago but the kernel of RHEL8 drops btrfs filesystem because of some reasons.
It is just a reason used to explain why I want to drop the kernel version check.
Quoted 31 lines
Quoted 3 lines
b)
tst_syscall()has checked ENOSYS error so we can simplefsopen_supported_by_kernel()by replacingsyscall()withtst_syscalls().Well, one of the benefits of
fsopen_supported_by_kernel()was to reduce a bit of duplicity. Even if the implementation is like TEST andSAFE_CLOSE(), it's a fewer lines (+ function name as a self docs).void
fsopen_supported_by_kernel(void){ TEST(tst_syscall(__NR_fsopen, NULL, 0)); if (TST_RET != -1) SAFE_CLOSE(TST_RET); }For your change for
pidfd_open03.c:static void setup(void)
{ int pidfd = -1; // Check if pidfd_open(2) is not supported pidfd = tst_syscall(__NR_pidfd_open, getpid(), 0); if (pidfd != -1) SAFE_CLOSE(pidfd); }static struct tst_test test = {(quoted diff) +1
-1- .min_kver = "5.3", + .setup = setup,
Quoted 1 line
How about to call the function
pidfd_open_supported_by_kernel()?
OK
Quoted 1 line
Than you can remove the comment (which BTW should use C style /* */).
OK
Quoted 1 line
And IMHO you don't have to assign pidfd to -1.
In pidfd_open_supported_by_kernel(), do you want to drop 'pidfd = -1' directly or drop 'pidfd = -1' by using TEST()?
Best Regards,
Xiao Yang
Quoted 7 lines
Kind regards,
Petr.
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Hi Yang,
Quoted 1 line
Thanks a lot for your quick reply.
Thanks for a patience (we're not working just on LTP unfortunately).
Quoted 2 lines
Resetting errno may not necessary because errno will be set again when fd == -1.
Agree, I'm just careful, thus asking :).
Quoted 11 lines
Quoted 10 lines
Quoted 9 lines
2)
tst_syscall()is enough to check the support ofpidfd_open()and I don't want to define check function asfsopen_supported_by_kernel()does.
Do you think so?BTW:
I don't like the implementation offsopen_supported_by_kernel():
a) syscall()/tst_syscall() is enough to check the support ofpidfd_open(2)and 'tst_kvercmp(5, 2, 0))< 0' will skip the check if+1 for
tst_syscall()
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
a kernel on distribution is newer than v5.2 but drop the support of
pidfd_open(2)on purpose."drop support of
pidfd_open(2)on purpose": would anybody has a reason to do that?As my pervious mail said, It is just a possible situation? for example:
Upstream kernel introduces btrfs filesystem long long ago but the kernel of RHEL8 drops btrfs filesystem because of some reasons.
I guess filesystem changes are the most frequent. But as I said, I wouldn't mind this implementation:
void fsopen_supported_by_kernel(void)
{
TEST(tst_syscall(__NR_fsopen, NULL, 0));
if (TST_RET != -1)
SAFE_CLOSE(TST_RET);
}Quoted 2 lines
It is just a reason used to explain why I want to drop the kernel version check.
...
Quoted 4 lines
Quoted 1 line
How about to call the function
pidfd_open_supported_by_kernel()?OK
Quoted 8 lines
Quoted 1 line
Than you can remove the comment (which BTW should use C style /* */).
OK
Quoted 1 line
And IMHO you don't have to assign pidfd to -1.
In
pidfd_open_supported_by_kernel(), do you want to drop 'pidfd = -1' directly or drop 'pidfd = -1' by usingTEST()?
I meant (as it's always assigned by the call, it's just a nit.):
-int pidfd = -1;
+int pidfd;
Kind regards,
Petr
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Hi Yang,
one more note:
Quoted 11 lines
Quoted 3 lines
As my pervious mail said, It is just a possible situation? for example:
Upstream kernel introduces btrfs filesystem long long ago but the kernel of RHEL8 drops btrfs filesystem because of some reasons.I guess filesystem changes are the most frequent. But as I said, I wouldn't mind this implementation:
voidfsopen_supported_by_kernel(void){ TEST(tst_syscall(__NR_fsopen, NULL, 0)); if (TST_RET != -1) SAFE_CLOSE(TST_RET); }
BTW the same approach is used in include/lapi/openat2.h
void openat2_supported_by_kernel(void)
{
if ((tst_kvercmp(5, 6, 0)) < 0) {
/* Check if the syscall is backported on an older kernel */
TEST(syscall(__NR_openat2, -1, NULL, NULL, 0));
if (TST_RET == -1 && TST_ERR == ENOSYS)
tst_brk(TCONF, "Test not supported on kernel version < v5.6");
}
}and clone3_supported_by_kernel(). Both merged by Cyril.
To be honest I like this approach, because 1) it defines when new syscall was backported 2) if there is really problem that some functionality was removed, we can always handle it. But IMHO that's going to be rare (btrfs removed in RHEL 8 is IMHO because RHEL does not want to support it, but that would not happen for syscalls).
I'd also like to be consistent how we handle these new syscalls.
Kind regards,
Petr
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Quoted 27 lines · Petr Vorel
Hi Yang,
one more note:
Quoted 11 lines
Quoted 3 lines
As my pervious mail said, It is just a possible situation? for example:
Upstream kernel introduces btrfs filesystem long long ago but the kernel of RHEL8 drops btrfs filesystem because of some reasons.I guess filesystem changes are the most frequent. But as I said, I wouldn't mind this implementation:
voidfsopen_supported_by_kernel(void){ TEST(tst_syscall(__NR_fsopen, NULL, 0)); if (TST_RET != -1) SAFE_CLOSE(TST_RET); }BTW the same approach is used in
include/lapi/openat2.hvoid
openat2_supported_by_kernel(void){ if ((tst_kvercmp(5, 6, 0))< 0) { /* Check if the syscall is backported on an older kernel */ TEST(syscall(__NR_openat2, -1, NULL, NULL, 0)); if (TST_RET == -1&& TST_ERR == ENOSYS) tst_brk(TCONF, "Test not supported on kernel version< v5.6"); } }
Quoted 4 lines
and
clone3_supported_by_kernel(). Both merged by Cyril.To be honest I like this approach, because 1) it defines when new syscall was backported
Hi Petr?
Hmm, the reason seems a little weak, it can be done by adding a comment(e.g. "the syscall is introduced since v5.6.0").
2) if there is really problem that some functionality was removed, we
Quoted 3 lines
can always handle it. But IMHO that's going to be rare (btrfs removed in RHEL 8 is IMHO because RHEL does not want to support it, but that would not happen for syscalls).
Without the rare situation, I also think tst_syscall() is enough to check the support of syscall.
Quoted 2 lines
I'd also like to be consistent how we handle these new syscalls.
Agreed.
I also think if we can implement common func(e.g.syscall_supported_by_kernel()).
Best Regards,
Xiao Yang
Quoted 7 lines
Kind regards,
Petr.
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Hi Yang,
Quoted 5 lines
Quoted 2 lines
To be honest I like this approach, because 1) it defines when new syscall was backported
Hmm, the reason seems a little weak, it can be done by adding a comment(e.g. "the syscall is introduced since v5.6.0").
Sure, that would work as well.
Quoted 7 lines
2) if there is really problem that some functionality was removed, we
Quoted 3 lines
can always handle it. But IMHO that's going to be rare (btrfs removed in RHEL 8 is IMHO because RHEL does not want to support it, but that would not happen for syscalls).
Without the rare situation, I also think
tst_syscall()is enough to check the support of syscall.
Well, nothing that much important, but I'd like to hear the opinion of other maintainers. BTW We now concentrate on pre-release fixes.
Quoted 5 lines
Quoted 1 line
I'd also like to be consistent how we handle these new syscalls.
Agreed.
I also think if we can implement common func(e.g.
syscall_supported_by_kernel()).
Sure, feel free to send a patch (could be a macro).
Kind regards,
Petr
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Quoted 10 lines · Petr Vorel
Hi Yang,
Quoted 5 lines
Quoted 2 lines
To be honest I like this approach, because 1) it defines when new syscall was backported
Hmm, the reason seems a little weak, it can be done by adding a comment(e.g. "the syscall is introduced since v5.6.0").
Sure, that would work as well.
Quoted 1 line
2) if there is really problem that some functionality was removed, we
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
can always handle it. But IMHO that's going to be rare (btrfs removed in RHEL 8 is IMHO because RHEL does not want to support it, but that would not happen for syscalls).
Without the rare situation, I also think
tst_syscall()is enough to check the support of syscall.Well, nothing that much important, but I'd like to hear the opinion of other maintainers. BTW We now concentrate on pre-release fixes.
Hi Petr,
Sure.
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
I'd also like to be consistent how we handle these new syscalls.
Agreed.
I also think if we can implement common func(e.g.
syscall_supported_by_kernel()).Sure, feel free to send a patch (could be a macro).
OK, I will send a patch after the release.
Best Regards,
Xiao Yang
Quoted 8 lines
Kind regards,
Petr.
PATCH v2 2/2 syscalls/pidfd_open*.c: Drop .min_kver flag
In reply to Xiao Yang1) Drop .min_kver flag directly because of two following reasons:
a) pidfd_open(2) may be backported to old kernel which is less than v5.3 so kernel version check is meaningless.
b) tst_syscall() can report TCONF if pidfd_open(2) is not supported.
2) For pidfd_open03.c, check if pidfd_open(2) is not supported before calling fork().
--- testcases/kernel/syscalls/pidfd_open/pidfd_open01.c | 1 - testcases/kernel/syscalls/pidfd_open/pidfd_open02.c | 1 - testcases/kernel/syscalls/pidfd_open/pidfd_open03.c | 12 +++++++++++- 3 files changed, 11 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/pidfd_open/pidfd_open01.c +0 -1
@@ -29,6 +29,5 @@ static void run(void) }static struct tst_test test = { - .min_kver ="5.3" , .test_all = run, };
testcases/kernel/syscalls/pidfd_open/pidfd_open02.c +0 -1
@@ -51,7 +51,6 @@ static void run(unsigned int n) }static struct tst_test test = { - .min_kver ="5.3" , .tcnt =ARRAY_SIZE (tcases), .test = run, .setup = setup,
testcases/kernel/syscalls/pidfd_open/pidfd_open03.c +11 -1
@@ -49,8 +49,18 @@ static void run(void)tst_res (TPASS ,"pidfd_open() passed" ); } +static void setup (void ) +{ +int pidfd =-1 ; + +// Check if pidfd_open(2) is not supported + pidfd =tst_syscall (__NR_pidfd_open,getpid (),0 ); +if (pidfd !=-1 ) +SAFE_CLOSE (pidfd); +} +static struct tst_test test = { - .min_kver ="5.3" , + .setup = setup, .test_all = run, .forks_child =1 , .needs_checkpoints =1 ,
Signature · 1 line
2.21.0
PATCH v2 2/2 syscalls/pidfd_open*.c: Drop .min_kver flag
Quoted 9 lines · Xiao Yang
1) Drop .min_kver flag directly because of two following reasons:
a)pidfd_open(2)may be backported to old kernel which is less than v5.3 so kernel version check is meaningless.
b)tst_syscall()can report TCONF ifpidfd_open(2)is not supported.
2) Forpidfd_open03.c, check ifpidfd_open(2)is not supported before callingfork().Signed-off-by Xiao Yang <[email protected]>Reviewed-by Viresh Kumar <[email protected]>
You can not apply someone's tag without them explicitly asking you to.
Quoted 37 lines
--- testcases/kernel/syscalls/pidfd_open/pidfd_open01.c | 1 - testcases/kernel/syscalls/pidfd_open/pidfd_open02.c | 1 - testcases/kernel/syscalls/pidfd_open/pidfd_open03.c | 12 +++++++++++- 3 files changed, 11 insertions(+), 3 deletions(-)testcases/kernel/syscalls/pidfd_open/pidfd_open01.c +0
-1@@ -29,6 +29,5 @@ static void run(void) }static struct tst_test test = { - .min_kver ="5.3" , .test_all = run, };testcases/kernel/syscalls/pidfd_open/pidfd_open02.c +0
-1@@ -51,7 +51,6 @@ static void run(unsigned int n) }static struct tst_test test = { - .min_kver ="5.3" , .tcnt =ARRAY_SIZE (tcases), .test = run, .setup = setup,testcases/kernel/syscalls/pidfd_open/pidfd_open03.c +0
-0@@ -49,8 +49,18 @@ static void run(void)tst_res (TPASS ,"pidfd_open() passed" ); }
testcases/kernel/syscalls/pidfd_open/pidfd_open03.c static void run(void) · line 61
Quoted 10 lines
testcases/kernel/syscalls/pidfd_open/pidfd_open03.c +10
-0+static void setup (void ) +{ +int pidfd =-1 ; + +// Check if pidfd_open(2) is not supported + pidfd =tst_syscall (__NR_pidfd_open,getpid (),0 ); +if (pidfd !=-1 ) +SAFE_CLOSE (pidfd); +} +
This only fixes the 3rd test, the other two will have an issue now.
Quoted 10 lines
testcases/kernel/syscalls/pidfd_open/pidfd_open03.c +1
-1static struct tst_test test = { - .min_kver ="5.3" , + .setup = setup, .test_all = run, .forks_child =1 , .needs_checkpoints =1 ,Signature · 1 line
2.21.0
Signature · 1 line
viresh
PATCH v2 2/2 syscalls/pidfd_open*.c: Drop .min_kver flag
Quoted 8 lines · Viresh Kumar
Quoted 7 lines · Xiao Yang
1) Drop .min_kver flag directly because of two following reasons:
a)pidfd_open(2)may be backported to old kernel which is less than v5.3 so kernel version check is meaningless.
b)tst_syscall()can report TCONF ifpidfd_open(2)is not supported.
2) Forpidfd_open03.c, check ifpidfd_open(2)is not supported before callingfork().
Quoted 4 lines
Quoted 2 lines
Signed-off-by Xiao Yang<[email protected]>Reviewed-by Viresh Kumar<[email protected]>You can not apply someone's tag without them explicitly asking you to.
Hi Viresh,
OK, I can remove it.
Quoted 38 lines
Quoted 38 lines
--- testcases/kernel/syscalls/pidfd_open/pidfd_open01.c | 1 - testcases/kernel/syscalls/pidfd_open/pidfd_open02.c | 1 - testcases/kernel/syscalls/pidfd_open/pidfd_open03.c | 12 +++++++++++- 3 files changed, 11 insertions(+), 3 deletions(-)testcases/kernel/syscalls/pidfd_open/pidfd_open01.c +0
-1@@ -29,6 +29,5 @@ static void run(void) }static struct tst_test test = { - .min_kver ="5.3" , .test_all = run, };testcases/kernel/syscalls/pidfd_open/pidfd_open02.c +0
-1@@ -51,7 +51,6 @@ static void run(unsigned int n) }static struct tst_test test = { - .min_kver ="5.3" , .tcnt =ARRAY_SIZE (tcases), .test = run, .setup = setup,testcases/kernel/syscalls/pidfd_open/pidfd_open03.c +0
-0@@ -49,8 +49,18 @@ static void run(void)tst_res (TPASS ,"pidfd_open() passed" ); }
Quoted 12 lines
testcases/kernel/syscalls/pidfd_open/pidfd_open03.c static void run(void) · line 61
Quoted 10 lines
testcases/kernel/syscalls/pidfd_open/pidfd_open03.c +10
-0+static void setup (void ) +{ +int pidfd =-1 ; + +// Check if pidfd_open(2) is not supported + pidfd =tst_syscall (__NR_pidfd_open,getpid (),0 ); +if (pidfd !=-1 ) +SAFE_CLOSE (pidfd); +} +This only fixes the 3rd test, the other two will have an issue now.
Could you tell which issue happen? Thanks a lot.
The other two don't need the extra check because the implementation of pidfd_open() can do it well. For 3rd test, I want to check the support of pidfs_open() before doing fork().
Thanks,
Xiao Yang
Quoted 12 lines
Quoted 11 lines
testcases/kernel/syscalls/pidfd_open/pidfd_open03.c +1
-2static struct tst_test test = { - .min_kver ="5.3" , + .setup = setup, .test_all = run, .forks_child =1 , .needs_checkpoints =1 , --2.21.0
PATCH v2 2/2 syscalls/pidfd_open*.c: Drop .min_kver flag
Quoted 4 lines · Xiao Yang
Could you tell which issue happen? Thanks a lot.
The other two don't need the extra check because the implementation ofpidfd_open()can do it well. For 3rd test, I want to check the support ofpidfs_open()before doingfork().
What I meant was that the solution needs to be consistent across tests. For example, with the current change the run() function will run for all tests in pidfd_open02.c and print the message that syscall isn't supported, while it would be better to run it only once in setup and get done with it. i.e. 1 message instead of 3 similar ones.
Signature · 1 line
viresh
PATCH v2 2/2 syscalls/pidfd_open*.c: Drop .min_kver flag
? 2020/5/13 14:13, Viresh Kumar ??:
Quoted 7 lines · Xiao Yang
Quoted 4 lines
Could you tell which issue happen? Thanks a lot.
The other two don't need the extra check because the implementation ofpidfd_open()can do it well. For 3rd test, I want to check the support ofpidfs_open()before doingfork().What I meant was that the solution needs to be consistent across
Hi Viresh,
Current change can do correct check for pidfd_open[1-3] so don't need to add redundant check.
Quoted 5 lines
tests. For example, with the current change the
run()function will run for all tests inpidfd_open02.cand print the message that syscall isn't supported, while it would be better to run it only once in setup and get done with it. i.e. 1 message instead of 3 similar ones.
Are you sure?
Triggering first tst_brk(TCONF, ...) will break the whole test instead of a subtest.
Thanks,
Xiao Yang
PATCH v2 2/2 syscalls/pidfd_open*.c: Drop .min_kver flag
Quoted 7 lines · Xiao Yang
? 2020/5/13 14:13, Viresh Kumar ??:
Quoted 6 lines · Xiao Yang
Quoted 4 lines
Could you tell which issue happen? Thanks a lot.
The other two don't need the extra check because the implementation ofpidfd_open()can do it well. For 3rd test, I want to check the support ofpidfs_open()before doingfork().
Quoted 5 lines
Quoted 1 line
What I meant was that the solution needs to be consistent across
Hi Viresh,
Current change can do correct check for pidfd_open[1-3] so don't need to add redundant check.
How will a check from file 03.c check it for 01.c or 02.c ?
Quoted 10 lines
Quoted 5 lines
tests. For example, with the current change the
run()function will run for all tests inpidfd_open02.cand print the message that syscall isn't supported, while it would be better to run it only once in setup and get done with it. i.e. 1 message instead of 3 similar ones.Are you sure?
Triggering first
tst_brk(TCONF, ...)will break the whole test instead of a subtest.
Ahh, yes. I missed the tst_brk part :(
But I will still like it to be consistent across files. But anyway, whatever you and Cyril decide is fine :)
Thanks.
Signature · 1 line
viresh
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
In reply to Xiao YangHi!
Quoted 13 lines
pidfd_open(2)will set close-on-exec flag on the file descriptor as it manpage states, so check close-on-exec flag by fcntl(2).BTW:
I tried to pass (long)TST_RETtofcntl()but triggered the following
compiler warning, so pass (int) pidfd instead.
------------------------------------------------------
In file included from pidfd_open01.c:9:pidfd_open01.c: In function ???run???:../../../../include/tst_test.h:76:41: warning: format ???%i??? expects argument of type ???int???, but argument 5 has type ???long int??? [-Wformat=]
76 |tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
| ^~~~~~~~~../../../../include/tst_safe_macros.h:224:5: note: in expansion of macro ???tst_brk???
Quoted 4 lines
224 | tst_brk(TBROK | TERRNO, \ | ^~~~~~~pidfd_open01.c:20:9: note: in expansion of macro ???SAFE_FCNTL???
20 | flag =SAFE_FCNTL(TST_RET, F_GETFD);
You can either cast the TST_RET to int as SAFE_FCNTL((int)TST_RET, ...) or if you decide to store the pidfd into an int variable there is no added value in using the TEST() macro here so the code should just do pidfd = pidfd_open(...) and use the pidfd instead of TST_RET.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 syscalls/pidfd_open01.c: Add check for close-on-exec flag
Quoted 19 lines · Cyril Hrubis
Hi!
Quoted 10 lines
pidfd_open(2)will set close-on-exec flag on the file descriptor as it manpage states, so check close-on-exec flag by fcntl(2).BTW:
I tried to pass (long)TST_RETtofcntl()but triggered the following
compiler warning, so pass (int) pidfd instead.
------------------------------------------------------
In file included from pidfd_open01.c:9:pidfd_open01.c: In function ???run???:../../../../include/tst_test.h:76:41: warning: format ???%i??? expects argument of type ???int???, but argument 5 has type ???long int??? [-Wformat=]Quoted 7 lines
76 | tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\ | ^~~~~~~~~ ../../../../include/tst_safe_macros.h:224:5: note: in expansion of macro ???tst_brk??? 224 | tst_brk(TBROK | TERRNO, \ | ^~~~~~~ pidfd_open01.c:20:9: note: in expansion of macro ???SAFE_FCNTL??? 20 | flag = SAFE_FCNTL(TST_RET, F_GETFD);
Quoted 4 lines
You can either cast the
TST_RETto int asSAFE_FCNTL((int)TST_RET, ...)or if you decide to store the pidfd into an int variable there is no added value in using theTEST()macro here so the code should just do pidfd =pidfd_open(...)and use the pidfd instead ofTST_RET.
Hi Cyril,
Thanks for your reply.
I also think it is OK to replace TEST() and TST_RET directly.
Thanks,
Xiao Yang