]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Don't remove the stats timer
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Feb 2025 17:41:27 +0000 (17:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Feb 2025 17:41:27 +0000 (17:41 +0000)
We used to free the stats timer whenever the daemon lost the connection
to the build service. Although that should be supported, it could make
the event loop abort because of some unexpected conditions.

This patch simply allocates the timer once and we just arm and disarm it
as needed.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.c

index 3733e2f7af56fa6ff0c0b5e6cb1f01ffb31a6898..a2f9f47bbd9ef842babc4dfa9831c25dbb91a009 100644 (file)
@@ -702,10 +702,11 @@ static int pakfire_daemon_close(struct pakfire_xfer* xfer, int code, void* data)
        if (daemon->reconnect_holdoff > 60000000)
                daemon->reconnect_holdoff = 60000000;
 
-       // Destroy the stats timer
-       if (daemon->stats_timer) {
-               sd_event_source_unref(daemon->stats_timer);
-               daemon->stats_timer = NULL;
+       // Disable sending stats until we are connected
+       r = sd_event_source_set_enabled(daemon->stats_timer, SD_EVENT_OFF);
+       if (r < 0) {
+               ERROR(daemon->ctx, "Could not disable the stats timer: %s\n", strerror(-r));
+               return r;
        }
 
        return 0;
@@ -760,14 +761,6 @@ static int pakfire_daemon_connected(struct pakfire_xfer* xfer, void* data) {
        // Reset the holdoff timer
        daemon->reconnect_holdoff = 1000000;
 
-       // Submit stats
-       r = sd_event_add_time_relative(daemon->loop, &daemon->stats_timer,
-               CLOCK_MONOTONIC, 0, 0, pakfire_daemon_submit_stats, daemon);
-       if (r < 0) {
-               ERROR(daemon->ctx, "Could not register the stat timer: %s\n", strerror(-r));
-               return r;
-       }
-
        // Submit stats continuously
        r = sd_event_source_set_enabled(daemon->stats_timer, SD_EVENT_ON);
        if (r < 0) {
@@ -1197,6 +1190,21 @@ static int pakfire_daemon_setup_loop(struct pakfire_daemon* daemon) {
                return r;
        }
 
+       // Setup the stats timer
+       r = sd_event_add_time_relative(daemon->loop, &daemon->stats_timer,
+               CLOCK_MONOTONIC, 0, 0, pakfire_daemon_submit_stats, daemon);
+       if (r < 0) {
+               ERROR(daemon->ctx, "Could not register the stat timer: %s\n", strerror(-r));
+               return r;
+       }
+
+       // Disable sending stats until we are connected
+       r = sd_event_source_set_enabled(daemon->stats_timer, SD_EVENT_OFF);
+       if (r < 0) {
+               ERROR(daemon->ctx, "Could not disable the stats timer: %s\n", strerror(-r));
+               return r;
+       }
+
        return 0;
 }