1
0
gnome-software/gs-add-locking-to-the-repos-plugin.patch

65 lines
2.1 KiB
Diff
Raw Normal View History

From d39f372902875f2cd762df2489e761053e94c883 Mon Sep 17 00:00:00 2001
From: Kalev Lember <klember@redhat.com>
Date: Wed, 22 Nov 2017 23:17:58 +0100
Subject: 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 file changed, 7 insertions(+)
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)
--
cgit v0.12