Skip to content

Commit

Permalink
Change how rlimit is set
Browse files Browse the repository at this point in the history
Last release changed to using the systemd LimitNOFILE=16384. This also
has the effect of changing the hard rlimit to the same number. If we
instead call getrlimit and set the soft limit to the hard limit, we
can have more descriptors available.

Also correct the error detection of failed nice syscalls.
  • Loading branch information
RH-steve-grubb committed Jun 21, 2023
1 parent b9035d6 commit 00ebdf8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion init/fapolicyd.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Documentation=man:fapolicyd(8)

[Service]
OOMScoreAdjust=-1000
LimitNOFILE=16384
Type=forking
PIDFile=/run/fapolicyd.pid
ExecStartPre=/usr/sbin/fagenrules
Expand Down
11 changes: 10 additions & 1 deletion src/daemon/fapolicyd.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,21 @@ int main(int argc, const char *argv[])
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_FSIZE, &limit);
getrlimit(RLIMIT_NOFILE, &limit);
if (limit.rlim_max >= 16384)
limit.rlim_cur = limit.rlim_max;
else
limit.rlim_cur = 16834;
if (setrlimit(RLIMIT_NOFILE, &limit))
msg(LOG_WARNING, "Can't increase file number rlimit - %s",
strerror(errno));
else
msg(LOG_INFO, "Can handle %u file descriptors", limit.rlim_cur);

// get more time slices because everything is waiting on us
if (nice(-config.nice_val))
errno = 0;
nice(-config.nice_val);
if (errno)
msg(LOG_WARNING, "Couldn't adjust priority (%s)",
strerror(errno));

Expand Down

0 comments on commit 00ebdf8

Please sign in to comment.