]> git.ipfire.org Git - zone-sync.git/commitdiff
main: Add a counter to terminate the event loop
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 May 2026 14:14:08 +0000 (14:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 May 2026 14:14:08 +0000 (14:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
main.c

diff --git a/main.c b/main.c
index f712534bb3be8054b9d36d3df6e65942b34253ba..187ffc8121a6c0d204f98c396cb5184635a86573 100644 (file)
--- a/main.c
+++ b/main.c
@@ -48,6 +48,9 @@ typedef struct ctx {
        const char** zones;
        unsigned int num_zones;
 
+       // How many transfers are running?
+       unsigned int running;
+
        // Memory Context
        isc_mem_t* memctx;
 
@@ -157,6 +160,18 @@ static void setup_logging(void) {
        isc_log_setcontext(ctx.log);
 }
 
+static void zone_done(dns_zone_t* zone) {
+       // Release the zone from the manager
+    dns_zonemgr_releasezone(ctx.zonemgr, zone);
+
+       // Free the zone
+    dns_zone_detach(&zone);
+
+       // Terminate if we are all done
+       if (!--ctx.running)
+               isc_loopmgr_shutdown(ctx.loopmgr);
+}
+
 static void transfer_done(dns_zone_t* zone, uint32_t* serial, isc_result_t result) {
        int r;
 
@@ -180,11 +195,8 @@ static void transfer_done(dns_zone_t* zone, uint32_t* serial, isc_result_t resul
                        break;
        }
 
-       // Release the zone from the manager
-    dns_zonemgr_releasezone(ctx.zonemgr, zone);
-
-       // Free the zone
-    dns_zone_detach(&zone);
+       // We are done
+       zone_done(zone);
 }
 
 static int do_transfer(dns_zone_t* zone, uint32_t serial) {
@@ -260,6 +272,9 @@ static void do_zone(const char* name) {
        char path[PATH_MAX];
        int r;
 
+       // Increment counter
+       ctx.running++;
+
        // Create the origin
        origin = dns_fixedname_initname(&fixed);