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

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