blob: 39623c37d8cd1766fd3ad0d717da8565026d2672 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001From db57ddc1497e72947da2b14f471ab521478ef99d Mon Sep 17 00:00:00 2001
2From: Tommi Rantala <tommi.t.rantala@nokia.com>
3Date: Thu, 31 Jan 2019 19:49:00 +0200
4Subject: [PATCH] syscalls/setrlimit03.c: read /proc/sys/fs/nr_open for
5 RLIMIT_NOFILE limit
6
7Since kernel v2.6.25 RLIMIT_NOFILE limit is no longer hardcoded to
8NR_OPEN, but can be set via /proc/sys/fs/nr_open, see kernel commit
99cfe015aa424b3c003baba3841a60dd9b5ad319b ("get rid of NR_OPEN and
10introduce a sysctl_nr_open").
11
12nr_open default value is 1024*1024, so setrlimit03 has been passing fine
13on new kernels, only "unexpectedly succeeding" if nr_open is set to some
14larger value.
15
16Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
17Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
18
19Upstream-Status: Backport [db57ddc1497e ("syscalls/setrlimit03.c: read /proc/sys/fs/nr_open for RLIMIT_NOFILE limit")]
20
21Signed-off-by: He Zhe <zhe.he@windriver.com>
22---
23 testcases/kernel/syscalls/setrlimit/setrlimit03.c | 13 +++++++++++--
24 1 file changed, 11 insertions(+), 2 deletions(-)
25
26diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit03.c b/testcases/kernel/syscalls/setrlimit/setrlimit03.c
27index 29b52aa..12455fe 100644
28--- a/testcases/kernel/syscalls/setrlimit/setrlimit03.c
29+++ b/testcases/kernel/syscalls/setrlimit/setrlimit03.c
30@@ -35,7 +35,10 @@
31 # define NR_OPEN (1024*1024)
32 #endif
33
34+#define NR_OPEN_PATH "/proc/sys/fs/nr_open"
35+
36 static struct rlimit rlim1, rlim2;
37+static unsigned int nr_open = NR_OPEN;
38
39 static struct tcase {
40 struct rlimit *rlimt;
41@@ -51,7 +54,10 @@ static void verify_setrlimit(unsigned int n)
42
43 TEST(setrlimit(RLIMIT_NOFILE, tc->rlimt));
44 if (TST_RET != -1) {
45- tst_res(TFAIL, "call succeeded unexpectedly");
46+ tst_res(TFAIL, "call succeeded unexpectedly "
47+ "(nr_open=%u rlim_cur=%lu rlim_max=%lu)", nr_open,
48+ (unsigned long)(tc->rlimt->rlim_cur),
49+ (unsigned long)(tc->rlimt->rlim_max));
50 return;
51 }
52
53@@ -65,10 +71,13 @@ static void verify_setrlimit(unsigned int n)
54
55 static void setup(void)
56 {
57+ if (!access(NR_OPEN_PATH, F_OK))
58+ SAFE_FILE_SCANF(NR_OPEN_PATH, "%u", &nr_open);
59+
60 SAFE_GETRLIMIT(RLIMIT_NOFILE, &rlim1);
61 rlim2.rlim_max = rlim1.rlim_cur;
62 rlim2.rlim_cur = rlim1.rlim_max + 1;
63- rlim1.rlim_max = NR_OPEN + 1;
64+ rlim1.rlim_max = nr_open + 1;
65 }
66
67 static struct tst_test test = {
68--
692.7.4
70