summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/rlimits.cc
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2019-04-10 16:33:44 -0700
committerShentubot <shentubot@google.com>2019-04-10 16:34:50 -0700
commitc8368e477b8f2dedaadacbd6efbb455879c9b1d6 (patch)
tree70fb83188b5be26b755ef3af885fa78dcecec6fe /test/syscalls/linux/rlimits.cc
parent89cc8eef9ba6440a5f1772bb2cd200da9b4890d9 (diff)
rlimits test: don't exceed nr_open.
Even superuser cannot raise RLIMIT_NOFILE above /proc/sys/fs/nr_open, so start the test by lowering the limits before raising. Change-Id: Ied6021c64178a6cb9098088a1a3384db523a226f PiperOrigin-RevId: 242965249
Diffstat (limited to 'test/syscalls/linux/rlimits.cc')
-rw-r--r--test/syscalls/linux/rlimits.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/syscalls/linux/rlimits.cc b/test/syscalls/linux/rlimits.cc
index 5a6174d99..7b255d0f6 100644
--- a/test/syscalls/linux/rlimits.cc
+++ b/test/syscalls/linux/rlimits.cc
@@ -29,6 +29,12 @@ TEST(RlimitTest, SetRlimitHigher) {
struct rlimit rl = {};
EXPECT_THAT(getrlimit(RLIMIT_NOFILE, &rl), SyscallSucceeds());
+ // Lower the rlimit first, as it may be equal to /proc/sys/fs/nr_open, in
+ // which case even users with CAP_SYS_RESOURCE can't raise it.
+ rl.rlim_cur--;
+ rl.rlim_max--;
+ ASSERT_THAT(setrlimit(RLIMIT_NOFILE, &rl), SyscallSucceeds());
+
rl.rlim_max++;
EXPECT_THAT(setrlimit(RLIMIT_NOFILE, &rl), SyscallSucceeds());
}