diff --git a/lib/event.c b/lib/event.c index 6427705e90a3..0a625c7174f5 100644 --- a/lib/event.c +++ b/lib/event.c @@ -544,7 +544,8 @@ static void initializer(void) } #define STUPIDLY_LARGE_FD_SIZE 100000 -struct event_loop *event_master_create(const char *name) +#define FD_LIMIT_SIZE_FOR_VTYSH 1000 +struct event_loop *event_master_create(const char *name, bool limit_fds) { struct event_loop *rv; struct rlimit limit; @@ -570,6 +571,9 @@ struct event_loop *event_master_create(const char *name) rv->fd_limit = (int)limit.rlim_cur; } + if (limit_fds) + rv->fd_limit = MIN(FD_LIMIT_SIZE_FOR_VTYSH, rv->fd_limit); + if (rv->fd_limit > STUPIDLY_LARGE_FD_SIZE) zlog_warn("FD Limit set: %u is stupidly large. Is this what you intended? Consider using --limit-fds", rv->fd_limit); diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index 1ffa5934aa5b..0a4493adbfca 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -78,7 +78,7 @@ struct frr_pthread *frr_pthread_new(const struct frr_pthread_attr *attr, /* initialize mutex */ pthread_mutex_init(&fpt->mtx, NULL); /* create new thread master */ - fpt->master = event_master_create(name); + fpt->master = event_master_create(name, false); /* set attributes */ fpt->attr = *attr; name = (name ? name : "Anonymous thread"); diff --git a/lib/frrevent.h b/lib/frrevent.h index 998727f0799d..b3c9c41e956d 100644 --- a/lib/frrevent.h +++ b/lib/frrevent.h @@ -223,7 +223,15 @@ static inline unsigned long timeval_elapsed(struct timeval a, struct timeval b) }) /* end */ /* Prototypes. */ -extern struct event_loop *event_master_create(const char *name); + +/* + * event_master_create + * inputs: + * name - The name of the event system that is being created + * limit_fds - Ignore the systems built in limit and use 1000 or + * the actual value which ever is lesser + */ +extern struct event_loop *event_master_create(const char *name, bool limit_fds); void event_master_set_name(struct event_loop *master, const char *name); extern void event_master_free(struct event_loop *m); extern void event_master_free_unused(struct event_loop *m); diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c index abd42f359f05..8f3bc2bd0aed 100644 --- a/lib/grammar_sandbox_main.c +++ b/lib/grammar_sandbox_main.c @@ -29,7 +29,7 @@ int main(int argc, char **argv) { struct event event; - master = event_master_create(NULL); + master = event_master_create(NULL, true); zlog_aux_init("NONE: ", LOG_DEBUG); diff --git a/lib/libfrr.c b/lib/libfrr.c index 9e472054dd5a..241c08b9aaa8 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -776,7 +776,7 @@ struct event_loop *frr_init(void) zprivs_init(di->privs); - master = event_master_create(NULL); + master = event_master_create(NULL, false); signal_init(master, di->n_signals, di->signals); hook_call(frr_early_init, master); diff --git a/ospfclient/ospfclient.c b/ospfclient/ospfclient.c index 24ff08561d7b..f258e56ce016 100644 --- a/ospfclient/ospfclient.c +++ b/ospfclient/ospfclient.c @@ -293,7 +293,7 @@ int main(int argc, char *argv[]) /* Initialization */ zprivs_preinit(&ospfd_privs); zprivs_init(&ospfd_privs); - master = event_master_create(NULL); + master = event_master_create(NULL, true); /* Open connection to OSPF daemon */ oclient = ospf_apiclient_connect(args[1], ASYNCPORT); diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index b1299780db53..b2858bd4de4c 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -236,7 +236,7 @@ static void vtysh_rl_run(void) struct event thread; bool suppress_warnings = true; - master = event_master_create(NULL); + master = event_master_create(NULL, true); rl_callback_handler_install(vtysh_prompt(), vtysh_rl_callback); event_add_read(master, vtysh_rl_read, &suppress_warnings, STDIN_FILENO,