From c8368e477b8f2dedaadacbd6efbb455879c9b1d6 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Wed, 10 Apr 2019 16:33:44 -0700 Subject: 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 --- test/syscalls/linux/rlimits.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test') 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()); } -- cgit v1.2.3