From a0925ade5a8f3668860b108539ee4076b448dfa3 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 7 Feb 2024 08:09:46 -0500 Subject: [PATCH] lib, ospfclient, tests, vtysh: Allow for a minimum fd poll size There exists cases where just honoring the FD_LIMIT size as given to us by the operating system makes no sense. Let's just make a switch to allow for this for things like vtysh and ospfclient which will never have 1k files open at any given time. Fixes: #15315 Signed-off-by: Donald Sharp --- lib/event.c | 6 +++++- lib/frr_pthread.c | 2 +- lib/frrevent.h | 10 +++++++++- lib/grammar_sandbox_main.c | 2 +- lib/libfrr.c | 2 +- ospfclient/ospfclient.c | 2 +- tests/bgpd/test_aspath.c | 2 +- tests/bgpd/test_capability.c | 2 +- tests/bgpd/test_mp_attr.c | 2 +- tests/bgpd/test_mpath.c | 2 +- tests/bgpd/test_packet.c | 2 +- tests/bgpd/test_peer_attr.c | 2 +- tests/helpers/c/main.c | 2 +- tests/isisd/test_isis_spf.c | 2 +- tests/lib/cli/common_cli.c | 2 +- tests/lib/fuzz_zlog.c | 2 +- tests/lib/northbound/test_oper_data.c | 2 +- tests/lib/test_assert.c | 2 +- tests/lib/test_segv.c | 2 +- tests/lib/test_sig.c | 2 +- tests/lib/test_timer_correctness.c | 2 +- tests/lib/test_timer_performance.c | 2 +- tests/lib/test_zmq.c | 2 +- tests/ospfd/test_ospf_spf.c | 2 +- vtysh/vtysh_main.c | 2 +- 25 files changed, 37 insertions(+), 25 deletions(-) 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/tests/bgpd/test_aspath.c b/tests/bgpd/test_aspath.c index 29d2e4cf6e29..9e62a215b486 100644 --- a/tests/bgpd/test_aspath.c +++ b/tests/bgpd/test_aspath.c @@ -1406,7 +1406,7 @@ int main(void) { int i = 0; qobj_init(); - bgp_master_init(event_master_create(NULL), BGP_SOCKET_SNDBUF_SIZE, + bgp_master_init(event_master_create(NULL, true), BGP_SOCKET_SNDBUF_SIZE, list_new()); master = bm->master; bgp_option_set(BGP_OPT_NO_LISTEN); diff --git a/tests/bgpd/test_capability.c b/tests/bgpd/test_capability.c index 1ee47a38e457..0bb452975d06 100644 --- a/tests/bgpd/test_capability.c +++ b/tests/bgpd/test_capability.c @@ -926,7 +926,7 @@ int main(void) term_bgp_debug_as4 = -1UL; qobj_init(); - master = event_master_create(NULL); + master = event_master_create(NULL, true); bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new()); vrf_init(NULL, NULL, NULL, NULL); bgp_option_set(BGP_OPT_NO_LISTEN); diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c index cebdda9e5c71..8322b90daf4e 100644 --- a/tests/bgpd/test_mp_attr.c +++ b/tests/bgpd/test_mp_attr.c @@ -1070,7 +1070,7 @@ int main(void) qobj_init(); cmd_init(0); bgp_vty_init(); - master = event_master_create("test mp attr"); + master = event_master_create("test mp attr", true); bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new()); vrf_init(NULL, NULL, NULL, NULL); bgp_option_set(BGP_OPT_NO_LISTEN); diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c index ebbe3ac3e28f..c869ea831f49 100644 --- a/tests/bgpd/test_mpath.c +++ b/tests/bgpd/test_mpath.c @@ -379,7 +379,7 @@ int all_tests_count = array_size(all_tests); static int global_test_init(void) { qobj_init(); - master = event_master_create(NULL); + master = event_master_create(NULL, true); zclient = zclient_new(master, &zclient_options_default, NULL, 0); bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new()); vrf_init(NULL, NULL, NULL, NULL); diff --git a/tests/bgpd/test_packet.c b/tests/bgpd/test_packet.c index e050fd4c711b..1aee0f3d4319 100644 --- a/tests/bgpd/test_packet.c +++ b/tests/bgpd/test_packet.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) qobj_init(); bgp_attr_init(); - master = event_master_create(NULL); + master = event_master_create(NULL, true); bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new()); vrf_init(NULL, NULL, NULL, NULL); bgp_option_set(BGP_OPT_NO_LISTEN); diff --git a/tests/bgpd/test_peer_attr.c b/tests/bgpd/test_peer_attr.c index 12c2f1103abe..7551b76e0590 100644 --- a/tests/bgpd/test_peer_attr.c +++ b/tests/bgpd/test_peer_attr.c @@ -1351,7 +1351,7 @@ static void bgp_startup(void) zprivs_preinit(&bgpd_privs); zprivs_init(&bgpd_privs); - master = event_master_create(NULL); + master = event_master_create(NULL, true); nb_init(master, NULL, 0, false); bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new()); bgp_option_set(BGP_OPT_NO_LISTEN); diff --git a/tests/helpers/c/main.c b/tests/helpers/c/main.c index fdda7f1e2a28..348fe5353b78 100644 --- a/tests/helpers/c/main.c +++ b/tests/helpers/c/main.c @@ -93,7 +93,7 @@ int main(int argc, char **argv) progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]); /* master init. */ - master = event_master_create(NULL); + master = event_master_create(NULL, true); while (1) { int opt; diff --git a/tests/isisd/test_isis_spf.c b/tests/isisd/test_isis_spf.c index 4ea28cda2ff8..7e2f2a48326c 100644 --- a/tests/isisd/test_isis_spf.c +++ b/tests/isisd/test_isis_spf.c @@ -526,7 +526,7 @@ int main(int argc, char **argv) } /* master init. */ - master = event_master_create(NULL); + master = event_master_create(NULL, true); isis_master_init(master); /* Library inits. */ diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c index f9f584f450f6..8813148856ed 100644 --- a/tests/lib/cli/common_cli.c +++ b/tests/lib/cli/common_cli.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) umask(0027); /* master init. */ - master = event_master_create(NULL); + master = event_master_create(NULL, true); zlog_aux_init("NONE: ", test_log_prio); diff --git a/tests/lib/fuzz_zlog.c b/tests/lib/fuzz_zlog.c index d308f8eb2f7e..45b353d4577b 100644 --- a/tests/lib/fuzz_zlog.c +++ b/tests/lib/fuzz_zlog.c @@ -94,7 +94,7 @@ int main(int argc, char **argv) cfg->fd = fd; cmd_hostname_set("TEST"); - cfg->master = event_master_create("TEST"); + cfg->master = event_master_create("TEST", true); zlog_5424_apply_dst(cfg); diff --git a/tests/lib/northbound/test_oper_data.c b/tests/lib/northbound/test_oper_data.c index 8f7e7c5f8c71..6979c6a48a9e 100644 --- a/tests/lib/northbound/test_oper_data.c +++ b/tests/lib/northbound/test_oper_data.c @@ -405,7 +405,7 @@ int main(int argc, char **argv) umask(0027); /* master init. */ - master = event_master_create(NULL); + master = event_master_create(NULL, true); zlog_aux_init("NONE: ", ZLOG_DISABLED); diff --git a/tests/lib/test_assert.c b/tests/lib/test_assert.c index 4440075b41fe..bc314be52831 100644 --- a/tests/lib/test_assert.c +++ b/tests/lib/test_assert.c @@ -39,7 +39,7 @@ int main(int argc, char **argv) assertf(number > 1, "(B) the number was %d", number); /* set up SIGABRT handler */ - master = event_master_create("test"); + master = event_master_create("test", true); signal_init(master, 0, NULL); func_for_bt(number); diff --git a/tests/lib/test_segv.c b/tests/lib/test_segv.c index 5d2f451ebd9e..48f137be7ec8 100644 --- a/tests/lib/test_segv.c +++ b/tests/lib/test_segv.c @@ -56,7 +56,7 @@ static void threadfunc(struct event *thread) int main(void) { - master = event_master_create(NULL); + master = event_master_create(NULL, true); signal_init(master, array_size(sigs), sigs); zlog_aux_init("NONE: ", LOG_DEBUG); diff --git a/tests/lib/test_sig.c b/tests/lib/test_sig.c index 2bd7f309766e..1dec76d43cf7 100644 --- a/tests/lib/test_sig.c +++ b/tests/lib/test_sig.c @@ -40,7 +40,7 @@ struct event t; int main(void) { - master = event_master_create(NULL); + master = event_master_create(NULL, true); signal_init(master, array_size(sigs), sigs); zlog_aux_init("NONE: ", LOG_DEBUG); diff --git a/tests/lib/test_timer_correctness.c b/tests/lib/test_timer_correctness.c index 04c05168890d..5163893dd3b5 100644 --- a/tests/lib/test_timer_correctness.c +++ b/tests/lib/test_timer_correctness.c @@ -97,7 +97,7 @@ int main(int argc, char **argv) struct event t; struct timeval **alarms; - master = event_master_create(NULL); + master = event_master_create(NULL, true); log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; log_buf_pos = 0; diff --git a/tests/lib/test_timer_performance.c b/tests/lib/test_timer_performance.c index 3ace076b4327..61292f5f1f83 100644 --- a/tests/lib/test_timer_performance.c +++ b/tests/lib/test_timer_performance.c @@ -34,7 +34,7 @@ int main(int argc, char **argv) struct timeval tv_start, tv_lap, tv_stop; unsigned long t_schedule, t_remove; - master = event_master_create(NULL); + master = event_master_create(NULL, true); prng = prng_new(0); timers = calloc(SCHEDULE_TIMERS, sizeof(*timers)); diff --git a/tests/lib/test_zmq.c b/tests/lib/test_zmq.c index 2cd9d47cb4d4..282e8624261e 100644 --- a/tests/lib/test_zmq.c +++ b/tests/lib/test_zmq.c @@ -266,7 +266,7 @@ static void run_server(int syncfd) char dummy = 0; struct event t; - master = event_master_create(NULL); + master = event_master_create(NULL, true); signal_init(master, array_size(sigs), sigs); frrzmq_init(); diff --git a/tests/ospfd/test_ospf_spf.c b/tests/ospfd/test_ospf_spf.c index 932763100b33..fe7aca9028e0 100644 --- a/tests/ospfd/test_ospf_spf.c +++ b/tests/ospfd/test_ospf_spf.c @@ -274,7 +274,7 @@ int main(int argc, char **argv) } /* master init. */ - master = event_master_create(NULL); + master = event_master_create(NULL, true); /* Library inits. */ cmd_init(1); 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,