Skip to content

Commit

Permalink
lib, ospfclient, 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 9bedb67
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 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 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 9bedb67

Please sign in to comment.