From: Arran Cudbard-Bell Date: Thu, 13 Jul 2023 21:17:50 +0000 (-0600) Subject: network: Use an explicit exiting flag instead of a started flag X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8814c32e2c1fefb92a6480bea5239c042f49df46;p=thirdparty%2Ffreeradius-server.git network: Use an explicit exiting flag instead of a started flag --- diff --git a/src/lib/io/control.c b/src/lib/io/control.c index cd680112c3f..4fee2a6997e 100644 --- a/src/lib/io/control.c +++ b/src/lib/io/control.c @@ -383,7 +383,8 @@ ssize_t fr_control_message_pop(fr_atomic_queue_t *aq, uint32_t *p_id, void *data if (!fr_atomic_queue_pop(aq, (void **) &m)) return 0; - fr_assert(m->status == FR_CONTROL_MESSAGE_USED); + fr_assert_msg(m->status == FR_CONTROL_MESSAGE_USED, "Bad control message state, expected %u got %u", + FR_CONTROL_MESSAGE_USED, m->status); /* * There isn't enough room to store the data, die. diff --git a/src/lib/io/network.c b/src/lib/io/network.c index adbdc5bf183..08a4fa0220a 100644 --- a/src/lib/io/network.c +++ b/src/lib/io/network.c @@ -114,7 +114,6 @@ struct fr_network_s { pthread_t thread_id; //!< for self - bool started; //!< Set to true when the first worker is added. bool suspended; //!< whether or not we're suspended. fr_log_t const *log; //!< log destination @@ -144,6 +143,8 @@ struct fr_network_s { int signal_pipe[2]; //!< Pipe for signalling the worker in an orderly way. ///< This is more deterministic than using async signals. + bool exiting; //!< are we exiting? + fr_network_config_t config; //!< configuration fr_network_worker_t *workers[MAX_WORKERS]; //!< each worker }; @@ -1507,7 +1508,6 @@ static void fr_network_worker_started_callback(void *ctx, void const *data, size fr_channel_set_recv_reply(w->channel, nr, fr_network_recv_reply); nr->num_workers++; - nr->started = true; /* * Insert the worker into the array of workers. @@ -1732,6 +1732,7 @@ int fr_network_destroy(fr_network_t *nr) (void) fr_event_pre_delete(nr->el, fr_network_pre_event, nr); (void) fr_event_post_delete(nr->el, fr_network_post_event, nr); + nr->exiting = true; fr_event_fd_delete(nr->el, nr->signal_pipe[0], FR_EVENT_FILTER_IO); return 0; @@ -1772,7 +1773,7 @@ static void _signal_pipe_read(UNUSED fr_event_list_t *el, int fd, UNUSED int fla */ void fr_network(fr_network_t *nr) { - while (likely(((nr->num_workers > 0) || !nr->started))) { + while (likely((nr->num_workers > 0) || !nr->exiting)) { bool wait_for_event; int num_events; @@ -1800,6 +1801,7 @@ void fr_network(fr_network_t *nr) fr_event_service(nr->el); } } + return; } /** Signal a network thread to exit