authorgravatar for vincent@rischmann.frVincent Rischmann <vincent@rischmann.fr> 2021-10-10 15:10:02+02:00
committergravatar for vincent@rischmann.frVincent Rischmann <vincent@rischmann.fr> 2021-11-16 20:36:50+01:00
logd7c770fb7f071543c21d91dc2d01f01df81f0cf6
tree320c9612fdd250a11d1cef536aec02e63adf04f8
parent353c59e6d5f32203ade301c609e20c1fa954f73d

os: fix getrlimit/setrlimit test for MIPS

This test can fail due to a fix in musl for 32 bit MIPS, where musl changes limits greater than -1UL/2 to RLIM_INFINITY. See http://git.musl-libc.org/cgit/musl/commit/src/misc/getrlimit.c?id=8258014fd1e34e942a549c88c7e022a00445c352 Depending on the system where the test is run getrlimit can return RLIM_INFINITY for example if RLIMIT_MEMLOCK is bigger than ~2GiB. If that happens, the setrlimit call will fail with PermissionDenied.

1 files changed, 13 insertions(+), 1 deletions(-)

lib/std/os/test.zig+13-1
......@@ -693,7 +693,19 @@ test "getrlimit and setrlimit" {
693693 inline for (std.meta.fields(os.rlimit_resource)) |field| {
694694 const resource = @intToEnum(os.rlimit_resource, field.value);
695695 const limit = try os.getrlimit(resource);
696 try os.setrlimit(resource, limit);
696
697 // On 32 bit MIPS musl includes a fix which changes limits greater than -1UL/2 to RLIM_INFINITY.
698 // See http://git.musl-libc.org/cgit/musl/commit/src/misc/getrlimit.c?id=8258014fd1e34e942a549c88c7e022a00445c352
699 //
700 // This happens for example if RLIMIT_MEMLOCK is bigger than ~2GiB.
701 // In that case the following the limit would be RLIM_INFINITY and the following setrlimit fails with EPERM.
702 if (comptime builtin.cpu.arch.isMIPS() and builtin.link_libc) {
703 if (limit.cur != os.linux.RLIM.INFINITY) {
704 try os.setrlimit(resource, limit);
705 }
706 } else {
707 try os.setrlimit(resource, limit);
708 }
697709 }
698710}
699711