All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v4] syscalls/pidfd_open01.c: Add check for close-on-exec flag
@ 2020-07-20  5:27 Xiao Yang
  2020-07-20  7:07 ` Petr Vorel
  2020-07-20  8:53 ` Viresh Kumar
  0 siblings, 2 replies; 4+ messages in thread
From: Xiao Yang @ 2020-07-20  5:27 UTC (permalink / raw)
  To: ltp

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).

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---

1) We don't care if the test uses the TEST() macro so just keep it.
2) Use bare fcntl() instead of SAFE_FCNTL() so that file descriptor
   can be closed when fcntl(F_GETFD) fails.

 .../kernel/syscalls/pidfd_open/pidfd_open01.c  | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
index 93bb86687..f40e9b624 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
@@ -3,21 +3,35 @@
  * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
  *
  * Description:
- * Basic pidfd_open() test, fetches the PID of the current process and tries to
- * get its file descriptor.
+ * Basic pidfd_open() test:
+ * 1) Fetch the PID of the current process and try to get its file descriptor.
+ * 2) Check that the close-on-exec flag is set on the file descriptor.
  */
+
+#include <unistd.h>
+#include <fcntl.h>
 #include "tst_test.h"
 #include "lapi/pidfd_open.h"
 
 static void run(void)
 {
+	int flag;
+
 	TEST(pidfd_open(getpid(), 0));
 
 	if (TST_RET == -1)
 		tst_brk(TFAIL | TTERRNO, "pidfd_open(getpid(), 0) failed");
 
+	flag = fcntl(TST_RET, F_GETFD);
+
 	SAFE_CLOSE(TST_RET);
 
+	if (flag == -1)
+		tst_brk(TFAIL | TERRNO, "fcntl(F_GETFD) failed");
+
+	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");
 }
 
-- 
2.21.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH v4] syscalls/pidfd_open01.c: Add check for close-on-exec flag
  2020-07-20  5:27 [LTP] [PATCH v4] syscalls/pidfd_open01.c: Add check for close-on-exec flag Xiao Yang
@ 2020-07-20  7:07 ` Petr Vorel
  2020-07-20  8:53 ` Viresh Kumar
  1 sibling, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2020-07-20  7:07 UTC (permalink / raw)
  To: ltp

Hi,

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

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH v4] syscalls/pidfd_open01.c: Add check for close-on-exec flag
  2020-07-20  5:27 [LTP] [PATCH v4] syscalls/pidfd_open01.c: Add check for close-on-exec flag Xiao Yang
  2020-07-20  7:07 ` Petr Vorel
@ 2020-07-20  8:53 ` Viresh Kumar
  2020-07-20 11:24   ` Xiao Yang
  1 sibling, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2020-07-20  8:53 UTC (permalink / raw)
  To: ltp

On 20-07-20, 13:27, Xiao Yang wrote:
> 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).
> 
> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
> ---
> 
> 1) We don't care if the test uses the TEST() macro so just keep it.
> 2) Use bare fcntl() instead of SAFE_FCNTL() so that file descriptor
>    can be closed when fcntl(F_GETFD) fails.
> 
>  .../kernel/syscalls/pidfd_open/pidfd_open01.c  | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH v4] syscalls/pidfd_open01.c: Add check for close-on-exec flag
  2020-07-20  8:53 ` Viresh Kumar
@ 2020-07-20 11:24   ` Xiao Yang
  0 siblings, 0 replies; 4+ messages in thread
From: Xiao Yang @ 2020-07-20 11:24 UTC (permalink / raw)
  To: ltp

Hi Petr, Viresh

Thanks a lot for your review, pushed. :-)

Thanks,

Xiao Yang

On 7/20/20 4:53 PM, Viresh Kumar wrote:
> On 20-07-20, 13:27, Xiao Yang wrote:
>> 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).
>>
>> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
>> ---
>>
>> 1) We don't care if the test uses the TEST() macro so just keep it.
>> 2) Use bare fcntl() instead of SAFE_FCNTL() so that file descriptor
>>     can be closed when fcntl(F_GETFD) fails.
>>
>>   .../kernel/syscalls/pidfd_open/pidfd_open01.c  | 18 ++++++++++++++++--
>>   1 file changed, 16 insertions(+), 2 deletions(-)
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-20 11:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20  5:27 [LTP] [PATCH v4] syscalls/pidfd_open01.c: Add check for close-on-exec flag Xiao Yang
2020-07-20  7:07 ` Petr Vorel
2020-07-20  8:53 ` Viresh Kumar
2020-07-20 11:24   ` Xiao Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.