Skip to content

Commit

Permalink
Expose the main event loop so modules can use it.
Browse files Browse the repository at this point in the history
Initialize, but do not start, event loop earlier.

Do it through a new API function that leaves room for enhancements
such as a second thread/event loop for modules that can do their
events in a threadsafe manner.  But don't actually do that yet.
  • Loading branch information
skids authored and arr2036 committed Mar 29, 2014
1 parent 286e328 commit 44c256d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/include/radiusd.h
Expand Up @@ -722,7 +722,14 @@ rad_listen_t *listener_find_byipaddr(fr_ipaddr_t const *ipaddr, int port,
int rad_status_server(REQUEST *request);

/* event.c */
int radius_event_init(CONF_SECTION *cs, bool spawn_flag);
typedef enum event_corral_t {
EVENT_CORRAL_MAIN = 0, //!< Always main thread event list
EVENT_CORRAL_AUX //!< Maybe main thread or one shared by modules
} event_corral_t;

fr_event_list_t *radius_event_list_corral(event_corral_t hint);
int radius_event_init(bool spawn_flag, bool aux_loops);
int radius_event_start(CONF_SECTION *cs, bool spawn_flag);
void radius_event_free(void);
int radius_event_process(void);
int event_new_fd(rad_listen_t *listener);
Expand Down
25 changes: 19 additions & 6 deletions src/main/process.c
Expand Up @@ -49,10 +49,15 @@ extern fr_cond_t *debug_condition;

static bool spawn_flag = false;
static bool just_started = true;
time_t fr_start_time;
time_t fr_start_time = (time_t)-1;
static fr_packet_list_t *pl = NULL;
static fr_event_list_t *el = NULL;

fr_event_list_t *radius_event_list_corral(UNUSED event_corral_t hint) {
/* Currently we do not run a second event loop for modules. */
return el;
}

static char const *action_codes[] = {
"INVALID",
"run",
Expand Down Expand Up @@ -941,14 +946,14 @@ STATE_MACHINE_DECL(request_common)

TRACE_STATE_MACHINE;
ASSERT_MASTER;

/*
* Bail out as early as possible.
*/
if (request->master_state == REQUEST_STOP_PROCESSING) {
request_done(request, REQUEST_DONE);
return;
}
}

switch (action) {
case FR_ACTION_DUP:
Expand Down Expand Up @@ -4287,16 +4292,24 @@ static void event_signal_handler(UNUSED fr_event_list_t *xel,
/*
* Externally-visibly functions.
*/
int radius_event_init(CONF_SECTION *cs, bool have_children)
int radius_event_init(UNUSED bool have_children, UNUSED bool aux_loops) {
el = fr_event_list_create(NULL, event_status);
if (!el) return 0;

return 1;
/* If have_children/threaded we could init an auxiliary loop */
}

int radius_event_start(CONF_SECTION *cs, bool have_children)
{
rad_listen_t *head = NULL;

if (el) return 0;
if (fr_start_time != (time_t)-1) return 0;

time(&fr_start_time);

el = fr_event_list_create(NULL, event_status);
if (!el) return 0;
if (fr_start_time == (time_t)-1) return 0;

pl = fr_packet_list_create(0);
if (!pl) return 0; /* leak el */
Expand Down
12 changes: 10 additions & 2 deletions src/main/radiusd.c
Expand Up @@ -317,6 +317,14 @@ int main(int argc, char *argv[])
version();
}

/*
* Initialize any event loops just enough so module instantiations
* can add fd/event to them, but do not start them yet.
*/
if (!radius_event_init(spawn_flag, 0)) {
exit(EXIT_FAILURE);
}

/* Read the configuration files, BEFORE doing anything else. */
if (read_mainconfig(0) < 0) {
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -437,9 +445,9 @@ int main(int argc, char *argv[])
radius_pid = getpid();

/*
* Initialize the event pool, including threads.
* Start the event loop(s) and threads.
*/
radius_event_init(mainconfig.config, spawn_flag);
radius_event_start(mainconfig.config, spawn_flag);

/*
* Now that we've set everything up, we can install the signal
Expand Down

0 comments on commit 44c256d

Please sign in to comment.