Skip to content

Commit

Permalink
lib, ospfclient, tests, vtysh: Allow for a minimum fd poll size
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
donaldsharp committed Feb 7, 2024
1 parent 7fe05d6 commit a0925ad
Show file tree
Hide file tree
Showing 25 changed files with 37 additions and 25 deletions.
6 changes: 5 additions & 1 deletion lib/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/frr_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 9 additions & 1 deletion lib/frrevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/grammar_sandbox_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion lib/libfrr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion ospfclient/ospfclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/bgpd/test_aspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/bgpd/test_capability.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/bgpd/test_mp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/bgpd/test_mpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/bgpd/test_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/bgpd/test_peer_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/isisd/test_isis_spf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/cli/common_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/fuzz_zlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/northbound/test_oper_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_segv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_timer_correctness.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_timer_performance.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_zmq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tests/ospfd/test_ospf_spf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion vtysh/vtysh_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a0925ad

Please sign in to comment.