All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/setrlimit03.c: read /proc/sys/fs/nr_open for RLIMIT_NOFILE limit
Date: Wed, 30 Jan 2019 17:15:14 +0100	[thread overview]
Message-ID: <20190130161514.GA27751@rei> (raw)
In-Reply-To: <20190130150047.26307-1-tt.rantala@gmail.com>

Hi!
> Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
> ---
>  testcases/kernel/syscalls/setrlimit/setrlimit03.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit03.c b/testcases/kernel/syscalls/setrlimit/setrlimit03.c
> index 29b52aa7f..643432bb4 100644
> --- a/testcases/kernel/syscalls/setrlimit/setrlimit03.c
> +++ b/testcases/kernel/syscalls/setrlimit/setrlimit03.c
> @@ -36,6 +36,7 @@
>  #endif
>  
>  static struct rlimit rlim1, rlim2;
> +static unsigned int nr_open;

I would have initialized the variable to NR_OPEN here.

>  static struct tcase {
>  	struct rlimit *rlimt;
> @@ -51,7 +52,10 @@ static void verify_setrlimit(unsigned int n)
>  
>  	TEST(setrlimit(RLIMIT_NOFILE, tc->rlimt));
>  	if (TST_RET != -1) {
> -		tst_res(TFAIL, "call succeeded unexpectedly");
> +		tst_res(TFAIL, "call succeeded unexpectedly "
> +			"(nr_open=%u rlim_cur=%lu rlim_max=%lu)", nr_open,
> +			(unsigned long)(tc->rlimt->rlim_cur),
> +			(unsigned long)(tc->rlimt->rlim_max));
>  		return;
>  	}
>  
> @@ -65,10 +69,16 @@ static void verify_setrlimit(unsigned int n)
>  
>  static void setup(void)
>  {
> +	if (tst_kvercmp(2, 6, 25) < 0) {
> +		nr_open = NR_OPEN;
> +	} else {
> +		SAFE_FILE_SCANF("/proc/sys/fs/nr_open", "%u", &nr_open);
> +	}

Can we do here without the explicit kernel version check?

What about:

#define NR_OPEN_PATH "/proc/sys/fs/nr_open"

...

	if (acess(NR_OPEN_PATH, F_OK))
		SAFE_FILE_SCANF(NR_OPEN_APTH, "%u", &nr_open);


Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2019-01-30 16:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-30 15:00 [LTP] [PATCH] syscalls/setrlimit03.c: read /proc/sys/fs/nr_open for RLIMIT_NOFILE limit Tommi Rantala
2019-01-30 16:15 ` Cyril Hrubis [this message]
2019-01-30 16:22   ` Tommi Rantala

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=20190130161514.GA27751@rei \
    --to=chrubis@suse.cz \
    --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.