summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2020-11-17 13:30:05 -0500
committerMark Stapp <mjs@voltanet.io>2020-11-18 15:34:35 -0500
commit1a9f340b6b63cbb9e19fc1372ef01e265d529e45 (patch)
treebeae6c483a575ad05062c57aba2fa2fa6800eab0 /lib/thread.c
parent85dcff6e412e5569dede949899d28f536c95ba98 (diff)
lib: add startup option to limit fds
Add a startup-time option to limit the number of fds used by the thread/event infrastructure. If nothing is configured, the system ulimit is used. Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/thread.c b/lib/thread.c
index e71fd74bd9..c886058355 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -36,6 +36,7 @@
#include "frr_pthread.h"
#include "lib_errors.h"
#include "libfrr_trace.h"
+#include "libfrr.h"
DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread")
DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master")
@@ -442,8 +443,14 @@ struct thread_master *thread_master_create(const char *name)
rv->name = XSTRDUP(MTYPE_THREAD_MASTER, name);
/* Initialize I/O task data structures */
- getrlimit(RLIMIT_NOFILE, &limit);
- rv->fd_limit = (int)limit.rlim_cur;
+
+ /* Use configured limit if present, ulimit otherwise. */
+ rv->fd_limit = frr_get_fd_limit();
+ if (rv->fd_limit == 0) {
+ getrlimit(RLIMIT_NOFILE, &limit);
+ rv->fd_limit = (int)limit.rlim_cur;
+ }
+
rv->read = XCALLOC(MTYPE_THREAD_POLL,
sizeof(struct thread *) * rv->fd_limit);