From: Michael Tremer Date: Wed, 25 Jun 2025 13:42:52 +0000 (+0000) Subject: daemon: Create the control connection as soon as the client is ready X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b03fedcf76d5529082c35ef825cfe4ebc5558ab4;p=pakfire.git daemon: Create the control connection as soon as the client is ready Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/daemon.c b/src/pakfire/daemon.c index d550ba80..178c1932 100644 --- a/src/pakfire/daemon.c +++ b/src/pakfire/daemon.c @@ -748,8 +748,7 @@ static int pakfire_daemon_connected(struct pakfire_xfer* xfer, void* data) { return 0; } -static int pakfire_daemon_connect(sd_event_source* s, uint64_t usec, void* data) { - struct pakfire_daemon* daemon = data; +static int pakfire_daemon_connect(struct pakfire_daemon* daemon) { struct pakfire_sysinfo sysinfo = {}; struct pakfire_cpuinfo cpuinfo = {}; struct pakfire_xfer* xfer = NULL; @@ -874,6 +873,16 @@ ERROR: return r; } +/* + Called when the client is ready and we can start making connections... +*/ +static int pakfire_daemon_ready(struct pakfire_client* client, void* data) { + struct pakfire_daemon* self = data; + + // Connect the control connection + return pakfire_daemon_connect(self); +} + // Currently we are not doing anything here. We just need to block SIGCHLD. static int pakfire_daemon_SIGCHLD(sd_event_source* s, const struct signalfd_siginfo* si, void* data) { return 0; @@ -988,13 +997,15 @@ static int pakfire_daemon_setup_loop(struct pakfire_daemon* daemon) { return r; } +#if 0 // Setup the reconnection timer r = sd_event_add_time_relative(daemon->loop, &daemon->connect_timer, - CLOCK_MONOTONIC, 0, 0, pakfire_daemon_connect, daemon); + CLOCK_MONOTONIC, 0, 0, pakfire_daemon_reconnect, daemon); if (r < 0) { ERROR(daemon->ctx, "Could not register the connection timer: %s\n", strerror(-r)); return r; } +#endif // Disable the reconnection timer until we are authenticated r = sd_event_source_set_enabled(daemon->connect_timer, SD_EVENT_OFF); @@ -1112,6 +1123,9 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct if (r < 0) goto ERROR; + // Register the ready callback + pakfire_client_set_ready_callback(d->client, pakfire_daemon_ready, d); + // Create the cgroup r = pakfire_cgroup_create(&d->cgroup, d->ctx, NULL, "pakfire-daemon", 0); if (r < 0)