Blame SOURCES/0004-daemon-don-t-send-spurious-change-signals-when-wtmp-.patch

baf615
From d93c4a3be8a56d55ecfc814eeef5c1bf1efe33de Mon Sep 17 00:00:00 2001
baf615
From: Ray Strode <rstrode@redhat.com>
baf615
Date: Wed, 27 Sep 2017 11:01:28 -0400
baf615
Subject: [PATCH 04/13] daemon: don't send spurious change signals when wtmp
baf615
 changes
baf615
baf615
Right now, we unintentionally send out a changed signal for
baf615
every tracked user anytime wtmp changes.
baf615
baf615
This commit fixes that.
baf615
---
baf615
 src/wtmp-helper.c | 22 +++++++++++++++++++---
baf615
 1 file changed, 19 insertions(+), 3 deletions(-)
baf615
baf615
diff --git a/src/wtmp-helper.c b/src/wtmp-helper.c
baf615
index 787480b..a1edffe 100644
baf615
--- a/src/wtmp-helper.c
baf615
+++ b/src/wtmp-helper.c
baf615
@@ -138,75 +138,91 @@ wtmp_helper_update_login_frequencies (GHashTable *users)
baf615
                                                    &key, &value)) {
baf615
                         accounting = g_new (UserAccounting, 1);
baf615
                         accounting->frequency = 0;
baf615
                         accounting->previous_logins = NULL;
baf615
 
baf615
                         g_hash_table_insert (login_hash, g_strdup (wtmp_entry->ut_user), accounting);
baf615
                 } else {
baf615
                         accounting = value;
baf615
                 }
baf615
 
baf615
                 accounting->frequency++;
baf615
                 accounting->time = wtmp_entry->ut_tv.tv_sec;
baf615
 
baf615
                 /* Add zero logout time to change it later on logout record */
baf615
                 previous_login = g_new (UserPreviousLogin, 1);
baf615
                 previous_login->id = g_strdup (wtmp_entry->ut_line);
baf615
                 previous_login->login_time = wtmp_entry->ut_tv.tv_sec;
baf615
                 previous_login->logout_time = 0;
baf615
                 accounting->previous_logins = g_list_prepend (accounting->previous_logins, previous_login);
baf615
 
baf615
                 g_hash_table_insert (logout_hash, g_strdup (wtmp_entry->ut_line), previous_login);
baf615
         }
baf615
 
baf615
         /* Last iteration */
baf615
         endutxent ();
baf615
 
baf615
         g_hash_table_iter_init (&iter, login_hash);
baf615
         while (g_hash_table_iter_next (&iter, &key, &value)) {
baf615
                 UserAccounting    *accounting = (UserAccounting *) value;
baf615
                 UserPreviousLogin *previous_login;
baf615
+                gboolean           changed = FALSE;
baf615
+                guint64            old_login_frequency;
baf615
+                guint64            old_login_time;
baf615
 
baf615
                 user = g_hash_table_lookup (users, key);
baf615
                 if (user == NULL) {
baf615
                         g_list_free_full (accounting->previous_logins, (GDestroyNotify) user_previous_login_free);
baf615
                         continue;
baf615
                 }
baf615
 
baf615
-                g_object_set (user, "login-frequency", accounting->frequency, NULL);
baf615
-                g_object_set (user, "login-time", accounting->time, NULL);
baf615
+                g_object_get (user,
baf615
+                              "login-frequency", &old_login_frequency,
baf615
+                              "login-time", &old_login_time,
baf615
+                              NULL);
baf615
+
baf615
+                if (old_login_frequency != accounting->frequency) {
baf615
+                        g_object_set (user, "login-frequency", accounting->frequency, NULL);
baf615
+                        changed = TRUE;
baf615
+                }
baf615
+
baf615
+                if (old_login_time != accounting->time) {
baf615
+                        g_object_set (user, "login-time", accounting->time, NULL);
baf615
+                        changed = TRUE;
baf615
+                }
baf615
 
baf615
                 builder = g_variant_builder_new (G_VARIANT_TYPE ("a(xxa{sv})"));
baf615
                 for (l = g_list_last (accounting->previous_logins); l != NULL; l = l->prev) {
baf615
                         previous_login = l->data;
baf615
 
baf615
                         builder2 = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
baf615
                         g_variant_builder_add (builder2, "{sv}", "type", g_variant_new_string (previous_login->id));
baf615
                         g_variant_builder_add (builder, "(xxa{sv})", previous_login->login_time, previous_login->logout_time, builder2);
baf615
                         g_variant_builder_unref (builder2);
baf615
                 }
baf615
                 g_object_set (user, "login-history", g_variant_new ("a(xxa{sv})", builder), NULL);
baf615
                 g_variant_builder_unref (builder);
baf615
                 g_list_free_full (accounting->previous_logins, (GDestroyNotify) user_previous_login_free);
baf615
 
baf615
-                user_changed (user);
baf615
+                if (changed)
baf615
+                        user_changed (user);
baf615
         }
baf615
 
baf615
         g_hash_table_unref (login_hash);
baf615
         g_hash_table_unref (logout_hash);
baf615
 }
baf615
 
baf615
 const gchar *
baf615
 wtmp_helper_get_path_for_monitor (void)
baf615
 {
baf615
         return PATH_WTMP;
baf615
 }
baf615
 
baf615
 #else /* HAVE_UTMPX_H */
baf615
 
baf615
 const gchar *
baf615
 wtmp_helper_get_path_for_monitor (void)
baf615
 {
baf615
         return NULL;
baf615
 }
baf615
 
baf615
 #endif /* HAVE_UTMPX_H */
baf615
-- 
baf615
2.14.1
baf615