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
This commit is contained in:
Kevin Krakauer
2019-04-10 16:34:50 -07:00
committed by Shentubot
parent 89cc8eef9b
commit c8368e477b
+6
View File
@@ -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());
}