From 46807a53ff160d5a6c4ecfd2847982d3221e1694 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 27 Aug 2024 12:37:08 +0100 Subject: [PATCH 1/2] Fix setrlimit maximums --- src/io/setrlimit/libimandrakit_setrlimit_stubs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/io/setrlimit/libimandrakit_setrlimit_stubs.c b/src/io/setrlimit/libimandrakit_setrlimit_stubs.c index d6ef5f3b..9a40f9f3 100644 --- a/src/io/setrlimit/libimandrakit_setrlimit_stubs.c +++ b/src/io/setrlimit/libimandrakit_setrlimit_stubs.c @@ -17,12 +17,16 @@ CAMLprim value caml_imandrakit_setrlimit(value _res, value _value) { int resource = resources[Int_val(_res)]; unsigned long limit = Int_val(_value); - const struct rlimit r = { - .rlim_cur = limit, - .rlim_max = limit, + struct rlimit old_limits; + if (getrlimit(resource, &old_limits) == 0) + CAMLreturn(false); + + const struct rlimit new_limits = { + .rlim_cur = limit < old_limits.rlim_cur ? limit : old_limits.rlim_cur, + .rlim_max = old_limits.rlim_max, }; - int res = setrlimit(resource, &r); + int res = setrlimit(resource, &new_limits); bool isok = (res == 0); CAMLreturn(Val_bool(isok)); From f90951fedfafb5b66e9fa51ef28bd5cdfe7dde17 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 27 Aug 2024 12:55:28 +0100 Subject: [PATCH 2/2] Fixes --- src/io/setrlimit/libimandrakit_setrlimit_stubs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/io/setrlimit/libimandrakit_setrlimit_stubs.c b/src/io/setrlimit/libimandrakit_setrlimit_stubs.c index 9a40f9f3..8f9c77dc 100644 --- a/src/io/setrlimit/libimandrakit_setrlimit_stubs.c +++ b/src/io/setrlimit/libimandrakit_setrlimit_stubs.c @@ -18,11 +18,11 @@ CAMLprim value caml_imandrakit_setrlimit(value _res, value _value) { unsigned long limit = Int_val(_value); struct rlimit old_limits; - if (getrlimit(resource, &old_limits) == 0) + if (getrlimit(resource, &old_limits) != 0) CAMLreturn(false); const struct rlimit new_limits = { - .rlim_cur = limit < old_limits.rlim_cur ? limit : old_limits.rlim_cur, + .rlim_cur = limit < old_limits.rlim_max ? limit : old_limits.rlim_max, .rlim_max = old_limits.rlim_max, };