[gnome-software] Add locking to the repos plugin



commit 1eb460391b939dee597bd97f80bab770f8923ac2
Author: Kalev Lember <klember redhat com>
Date:   Wed Nov 22 23:17:58 2017 +0100

    Add locking to the repos plugin
    
    ... so that we don't modify the priv->urls hash table concurrently from
    multiple threads.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1516536

 plugins/repos/gs-plugin-repos.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/plugins/repos/gs-plugin-repos.c b/plugins/repos/gs-plugin-repos.c
index 321f05c..468a6f3 100644
--- a/plugins/repos/gs-plugin-repos.c
+++ b/plugins/repos/gs-plugin-repos.c
@@ -26,6 +26,7 @@
 struct GsPluginData {
        GHashTable      *urls;          /* origin : url */
        GFileMonitor    *monitor;
+       GMutex           mutex;
        gchar           *reposdir;
        gboolean         valid;
 };
@@ -35,6 +36,8 @@ gs_plugin_initialize (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
 
+       g_mutex_init (&priv->mutex);
+
        /* for debugging and the self tests */
        priv->reposdir = g_strdup (g_getenv ("GS_SELF_TEST_REPOS_DIR"));
        if (priv->reposdir == NULL)
@@ -62,8 +65,10 @@ gs_plugin_destroy (GsPlugin *plugin)
                g_hash_table_unref (priv->urls);
        if (priv->monitor != NULL)
                g_object_unref (priv->monitor);
+       g_mutex_clear (&priv->mutex);
 }
 
+/* mutex must be held */
 static gboolean
 gs_plugin_repos_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
@@ -145,6 +150,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
        g_autoptr(GFile) file = g_file_new_for_path (priv->reposdir);
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
 
        /* watch for changes */
        priv->monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, cancellable, error);
@@ -168,6 +174,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
        const gchar *tmp;
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
 
        /* not required */
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME) == 0)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]