From e80447183e9dde5396e1a838259c6bf2b3f0e837 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 14 Feb 2025 17:41:27 +0000 Subject: [PATCH] daemon: Don't remove the stats timer 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 --- src/pakfire/daemon.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/pakfire/daemon.c b/src/pakfire/daemon.c index 3733e2f7..a2f9f47b 100644 --- a/src/pakfire/daemon.c +++ b/src/pakfire/daemon.c @@ -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; } -- 2.39.5