All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Yang <yangx.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/2] syscalls/pidfd_open01.c: Add check for close-on-exec flag
Date: Wed, 13 May 2020 10:28:13 +0800	[thread overview]
Message-ID: <5EBB5B3D.4020302@cn.fujitsu.com> (raw)
In-Reply-To: <20200513012626.1571-1-yangx.jy@cn.fujitsu.com>

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
On 2020/5/13 9:26, 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).
>
> 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);
> ------------------------------------------------------
>
> Signed-off-by: Xiao Yang<yangx.jy@cn.fujitsu.com>
> Reviewed-by: Viresh Kumar<viresh.kumar@linaro.org>
> ---
>   testcases/kernel/syscalls/pidfd_open/pidfd_open01.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
> index 93bb86687..ba1580bc7 100644
> --- a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
> +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
> @@ -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");
>   }
>




  parent reply	other threads:[~2020-05-13  2:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13  1:26 [LTP] [PATCH v2 1/2] syscalls/pidfd_open01.c: Add check for close-on-exec flag Xiao Yang
2020-05-13  1:26 ` [LTP] [PATCH v2 2/2] syscalls/pidfd_open*.c: Drop .min_kver flag Xiao Yang
2020-05-13  5:55   ` Viresh Kumar
2020-05-13  6:03     ` Xiao Yang
2020-05-13  6:13       ` Viresh Kumar
2020-05-13  6:31         ` Xiao Yang
2020-05-13  6:39           ` Viresh Kumar
2020-05-13  2:28 ` Xiao Yang [this message]
2020-05-13  9:20   ` [LTP] [PATCH v2 1/2] syscalls/pidfd_open01.c: Add check for close-on-exec flag Petr Vorel
2020-05-13 10:21     ` Xiao Yang
2020-05-13 10:30       ` Petr Vorel
2020-05-14  7:37         ` Petr Vorel
2020-05-14  9:43           ` Xiao Yang
2020-05-14 14:14             ` Petr Vorel
2020-05-14 14:27               ` Xiao Yang
2020-05-13 12:34 ` Cyril Hrubis
2020-05-13 13:12   ` Xiao Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5EBB5B3D.4020302@cn.fujitsu.com \
    --to=yangx.jy@cn.fujitsu.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.