From b9baa7113b7fc651feca317d691297abd9312e76 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Fri, 24 Mar 2023 12:16:46 -0400 Subject: daemon: Fix boot delay commit 836a9135fe2d8fdc7d6de3a6d11fb9a5fd05f926 made accountsservice reload wtmp less aggressively. Unfortunately, if wtmp is modified during boot, that added latency can delay the user list getting loaded. This commit addresses the problem by tracking how pressing the queued reload operation is, and makes it happen sooner if a higher priority request comes in. --- src/daemon.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/daemon.c b/src/daemon.c index 151f294..aa9d050 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -70,6 +70,14 @@ typedef enum DISPLAY_MANAGER_TYPE_LIGHTDM } DisplayManagerType; +typedef enum +{ + USER_RELOAD_TYPE_NONE = 0, + USER_RELOAD_TYPE_IMMEDIATELY, + USER_RELOAD_TYPE_SOON, + USER_RELOAD_TYPE_EVENTUALLY +} UserReloadType; + typedef struct { GDBusConnection *bus_connection; @@ -88,7 +96,9 @@ typedef struct GQueue *pending_list_cached_users; + UserReloadType reload_type; guint reload_id; + guint autologin_id; PolkitAuthority *authority; @@ -625,6 +635,7 @@ reload_users_timeout (Daemon *daemon) reload_users (daemon); priv->reload_id = 0; + priv->reload_type = USER_RELOAD_TYPE_NONE; g_queue_foreach (priv->pending_list_cached_users, (GFunc) finish_list_cached_users, NULL); @@ -698,6 +709,7 @@ queue_reload_users_eventually (Daemon *daemon) * and out in a continuous loop. */ priv->reload_id = g_timeout_add_seconds (10, (GSourceFunc) reload_users_timeout, daemon); + priv->reload_type = USER_RELOAD_TYPE_EVENTUALLY; } static void @@ -705,6 +717,11 @@ queue_reload_users_soon (Daemon *daemon) { DaemonPrivate *priv = daemon_get_instance_private (daemon); + if (priv->reload_type > USER_RELOAD_TYPE_SOON) { + g_source_remove (priv->reload_id); + priv->reload_id = 0; + } + if (priv->reload_id > 0) { return; } @@ -713,6 +730,7 @@ queue_reload_users_soon (Daemon *daemon) * /etc/shadow are changed at the same time, or repeatedly. */ priv->reload_id = g_timeout_add (500, (GSourceFunc) reload_users_timeout, daemon); + priv->reload_type = USER_RELOAD_TYPE_SOON; } static void @@ -720,11 +738,17 @@ queue_reload_users (Daemon *daemon) { DaemonPrivate *priv = daemon_get_instance_private (daemon); + if (priv->reload_type > USER_RELOAD_TYPE_IMMEDIATELY) { + g_source_remove (priv->reload_id); + priv->reload_id = 0; + } + if (priv->reload_id > 0) { return; } priv->reload_id = g_idle_add ((GSourceFunc) reload_users_timeout, daemon); + priv->reload_type = USER_RELOAD_TYPE_IMMEDIATELY; } static void @@ -1147,6 +1171,7 @@ daemon_list_cached_users (AccountsAccounts *accounts, if (priv->reload_id > 0) { /* reload pending -- finish call in reload_users_timeout */ g_queue_push_tail (priv->pending_list_cached_users, data); + queue_reload_users (daemon); } else { finish_list_cached_users (data); } -- cgit v1.2.1