]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
network: Use an explicit exiting flag instead of a started flag
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 13 Jul 2023 21:17:50 +0000 (15:17 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 13 Jul 2023 21:17:56 +0000 (15:17 -0600)
src/lib/io/control.c
src/lib/io/network.c

index cd680112c3f4c8023d9d7b66b1c7b8550a63c09d..4fee2a6997e5a1a60b9abedc40adfb75ff396304 100644 (file)
@@ -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.
index adbdc5bf183b82532bddebccc266e4a812f60aad..08a4fa0220a91a98ea26270c21d4bf3cb233fa41 100644 (file)
@@ -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