Skip to content

Commit

Permalink
Fix wrong rlimit handling
Browse files Browse the repository at this point in the history
  • Loading branch information
YutaroHayakawa committed May 28, 2020
1 parent 72a35c5 commit 20fd358
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ set_rlimit(struct ipft_symsdb *sdb)

/*
* Rough estimations for various file descriptors like eBPF
* program, maps or perf events and kprobe events.
* program, maps or perf events and kprobe events. This is
* the "required" number of file descriptors.
*/
nfiles = 32 + symsdb_get_sym2info_total(sdb);

Expand All @@ -91,12 +92,12 @@ set_rlimit(struct ipft_symsdb *sdb)
return -1;
}

if (lim.rlim_cur != RLIM_INFINITY) {
lim.rlim_cur += nfiles;
if (lim.rlim_cur < nfiles && lim.rlim_cur != RLIM_INFINITY) {
lim.rlim_cur = nfiles;
}

if (lim.rlim_max != RLIM_INFINITY) {
lim.rlim_max += nfiles;
if (lim.rlim_max != RLIM_INFINITY && lim.rlim_max < lim.rlim_cur) {
lim.rlim_max = lim.rlim_cur;
}

error = setrlimit(RLIMIT_NOFILE, &lim);
Expand Down

0 comments on commit 20fd358

Please sign in to comment.