Skip to content

Commit

Permalink
Merge pull request #11 from imandra-ai/christoph/fix-setrlimit
Browse files Browse the repository at this point in the history
Fix setrlimit maximums
  • Loading branch information
wintersteiger committed Aug 27, 2024
2 parents 4b70edf + f90951f commit 0c9b1c3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/io/setrlimit/libimandrakit_setrlimit_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_max ? limit : old_limits.rlim_max,
.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));
Expand Down

0 comments on commit 0c9b1c3

Please sign in to comment.