]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- fast-reload, keep list of pending print queue items in daemon struct.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 8 Dec 2023 14:12:36 +0000 (15:12 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 8 Dec 2023 14:12:36 +0000 (15:12 +0100)
daemon/daemon.c
daemon/daemon.h
daemon/remote.c
daemon/remote.h

index b7d7b631b25f1e57af7984e547c0bec93847edc9..9ee9a01a48300852d563b1c713227e5d239886c5 100644 (file)
@@ -844,6 +844,8 @@ daemon_cleanup(struct daemon* daemon)
        daemon_remote_clear(daemon->rc);
        if(daemon->fast_reload_thread)
                fast_reload_thread_stop(daemon->fast_reload_thread);
+       if(daemon->fast_reload_printq_list)
+               fast_reload_printq_list_delete(daemon->fast_reload_printq_list);
        for(i=0; i<daemon->num; i++)
                worker_delete(daemon->workers[i]);
        free(daemon->workers);
index 69e9a7280448da296e930ee2cf1ac17c1ca3892b..aeb68bd9443051087270f395831c884aafbddea9 100644 (file)
@@ -59,6 +59,7 @@ struct daemon_remote;
 struct respip_set;
 struct shm_main_info;
 struct fast_reload_thread;
+struct fast_reload_printq;
 
 #include "dnstap/dnstap_config.h"
 #ifdef USE_DNSTAP
@@ -149,6 +150,8 @@ struct daemon {
        int reuse_cache;
        /** the fast reload thread, or NULL */
        struct fast_reload_thread* fast_reload_thread;
+       /** the fast reload printq list */
+       struct fast_reload_printq* fast_reload_printq_list;
 };
 
 /**
index 896b4142434f941d736e2cdc0fd9501c5d3c8ab6..e01bdb3c454b8f009623fb91ba87cc05a5a07d77 100644 (file)
 static void fr_printq_delete(struct fast_reload_printq* printq);
 static void fr_main_perform_printout(struct fast_reload_thread* fr);
 static int fr_printq_empty(struct fast_reload_printq* printq);
+static void fr_printq_list_insert(struct fast_reload_printq* printq,
+       struct daemon* daemon);
+static void fr_printq_remove(struct fast_reload_printq* printq);
 
 static int
 remote_setup_ctx(struct daemon_remote* rc, struct config_file* cfg)
@@ -4029,6 +4032,9 @@ fast_reload_thread_desetup(struct fast_reload_thread* fast_reload_thread)
                if(fr_printq_empty(fast_reload_thread->printq)) {
                        fr_printq_delete(fast_reload_thread->printq);
                } else {
+                       fr_printq_list_insert(fast_reload_thread->printq,
+                               fast_reload_thread->worker->daemon);
+                       fast_reload_thread->printq = NULL;
                }
        }
        lock_basic_destroy(&fast_reload_thread->fr_output_lock);
@@ -4294,8 +4300,7 @@ fr_client_send_item(struct fast_reload_printq* printq)
                return 0;
        } else if(r == -1) {
                /* It failed, close comm point and stop sending. */
-               comm_point_delete(printq->client_cp);
-               printq->client_cp = NULL;
+               fr_printq_remove(printq);
                return 0;
        }
        printq->client_byte_count += r;
@@ -4339,12 +4344,13 @@ int fast_reload_client_callback(struct comm_point* ATTR_UNUSED(c), void* arg,
        int err, struct comm_reply* ATTR_UNUSED(rep))
 {
        struct fast_reload_printq* printq = (struct fast_reload_printq*)arg;
-       if(!printq->client_cp)
+       if(!printq->client_cp) {
+               fr_printq_remove(printq);
                return 0; /* the output is closed and deleted */
+       }
        if(err != NETEVENT_NOERROR) {
                verbose(VERB_ALGO, "fast reload client: error, close it");
-               comm_point_delete(printq->client_cp);
-               printq->client_cp = NULL;
+               fr_printq_remove(printq);
                return 0;
        }
 #ifdef HAVE_SSL
@@ -4360,6 +4366,11 @@ int fast_reload_client_callback(struct comm_point* ATTR_UNUSED(c), void* arg,
                fr_client_pickup_next_item(printq);
        }
        if(!printq->client_item) {
+               if(printq->in_list) {
+                       /* Nothing more to print, it can be removed. */
+                       fr_printq_remove(printq);
+                       return 0;
+               }
                /* Done with printing for now. */
                comm_point_stop_listening(printq->client_cp);
                return 0;
@@ -4382,6 +4393,11 @@ int fast_reload_client_callback(struct comm_point* ATTR_UNUSED(c), void* arg,
                        printq->client_byte_count = 0;
                }
                if(!printq->to_print->first) {
+                       if(printq->in_list) {
+                               /* Nothing more to print, it can be removed. */
+                               fr_printq_remove(printq);
+                               return 0;
+                       }
                        /* Done with printing for now. */
                        comm_point_stop_listening(printq->client_cp);
                        return 0;
@@ -4440,6 +4456,60 @@ fr_printq_empty(struct fast_reload_printq* printq)
        return 0;
 }
 
+/** fast reload printq, insert onto list */
+static void
+fr_printq_list_insert(struct fast_reload_printq* printq, struct daemon* daemon)
+{
+       if(printq->in_list)
+               return;
+       printq->next = daemon->fast_reload_printq_list;
+       if(printq->next)
+               printq->next->prev = printq;
+       printq->prev = NULL;
+       printq->in_list = 1;
+       daemon->fast_reload_printq_list = printq;
+}
+
+/** fast reload printq delete list */
+void
+fast_reload_printq_list_delete(struct fast_reload_printq* list)
+{
+       struct fast_reload_printq* printq = list, *next;
+       while(printq) {
+               next = printq->next;
+               fr_printq_delete(printq);
+               printq = next;
+       }
+}
+
+/** fast reload printq remove the item from the printq list */
+static void
+fr_printq_list_remove(struct fast_reload_printq* printq)
+{
+       struct daemon* daemon = printq->worker->daemon;
+       if(printq->prev == NULL)
+               daemon->fast_reload_printq_list = printq->next;
+       else    printq->prev->next = printq->next;
+       if(printq->next)
+               printq->next->prev = printq->prev;
+       printq->in_list = 0;
+}
+
+/** fast reload printq, remove the printq when no longer needed,
+ * like the stream is closed. */
+static void
+fr_printq_remove(struct fast_reload_printq* printq)
+{
+       if(!printq)
+               return;
+       if(printq->worker && printq->worker->daemon->fast_reload_thread &&
+               printq->worker->daemon->fast_reload_thread->printq == printq)
+               printq->worker->daemon->fast_reload_thread->printq = NULL;
+       if(printq->in_list)
+               fr_printq_list_remove(printq);
+       fr_printq_delete(printq);
+}
+
 /**
  * Fast reload thread, send a command to the thread. Blocking on timeout.
  * It handles received input from the thread, if any is received.
index cf07362cb8c2b2a178496300c92635121cfb16b4..82441598ea5f5516e543150c0b0d873ed578c34e 100644 (file)
@@ -317,4 +317,7 @@ void fast_reload_service_cb(int fd, short bits, void* arg);
 int fast_reload_client_callback(struct comm_point* c, void* arg, int err,
        struct comm_reply* rep);
 
+/** fast reload printq delete list */
+void fast_reload_printq_list_delete(struct fast_reload_printq* list);
+
 #endif /* DAEMON_REMOTE_H */