[glib/mcatanzaro/kfsb] gkeyfilesettingsbackend: check for errors when creating file monitors
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/mcatanzaro/kfsb] gkeyfilesettingsbackend: check for errors when creating file monitors
- Date: Tue, 23 Feb 2021 22:34:47 +0000 (UTC)
commit 26f6e3db9e896521af4bbd25d4f971ed25bf2e15
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Tue Feb 23 16:31:26 2021 -0600
gkeyfilesettingsbackend: check for errors when creating file monitors
File monitor creation may fail. We should check for this, rather than
ignoring it and then spewing criticals upon improperly assuming that we
have a valid GFileMonitor rather than NULL.
In practice, creating the GFileMonitors here fail when opening a large
number of tabs in Epiphany. I'm still investigating to see why, but it
doesn't matter for the purposes of this commit.
gio/gkeyfilesettingsbackend.c | 48 +++++++++++++++++++++++++++++++------------
1 file changed, 35 insertions(+), 13 deletions(-)
---
diff --git a/gio/gkeyfilesettingsbackend.c b/gio/gkeyfilesettingsbackend.c
index 485a25a14..094be3f91 100644
--- a/gio/gkeyfilesettingsbackend.c
+++ b/gio/gkeyfilesettingsbackend.c
@@ -605,19 +605,24 @@ g_keyfile_settings_backend_finalize (GObject *object)
g_hash_table_unref (kfsb->system_locks);
g_free (kfsb->defaults_dir);
- g_file_monitor_cancel (kfsb->file_monitor);
- g_object_unref (kfsb->file_monitor);
+ if (kfsb->file_monitor)
+ {
+ g_file_monitor_cancel (kfsb->file_monitor);
+ g_object_unref (kfsb->file_monitor);
+ }
g_object_unref (kfsb->file);
- g_file_monitor_cancel (kfsb->dir_monitor);
- g_object_unref (kfsb->dir_monitor);
+ if (kfsb->dir_monitor)
+ {
+ g_file_monitor_cancel (kfsb->dir_monitor);
+ g_object_unref (kfsb->dir_monitor);
+ }
g_object_unref (kfsb->dir);
g_free (kfsb->root_group);
g_free (kfsb->prefix);
- G_OBJECT_CLASS (g_keyfile_settings_backend_parent_class)
- ->finalize (object);
+ G_OBJECT_CLASS (g_keyfile_settings_backend_parent_class)->finalize (object);
}
static void
@@ -724,6 +729,7 @@ static void
g_keyfile_settings_backend_constructed (GObject *object)
{
GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
+ GError *error = NULL;
const char *path;
if (kfsb->file == NULL)
@@ -749,15 +755,31 @@ g_keyfile_settings_backend_constructed (GObject *object)
if (g_mkdir_with_parents (path, 0700) == -1)
g_warning ("Failed to create %s: %s", path, g_strerror (errno));
- kfsb->file_monitor = g_file_monitor (kfsb->file, G_FILE_MONITOR_NONE, NULL, NULL);
- kfsb->dir_monitor = g_file_monitor (kfsb->dir, G_FILE_MONITOR_NONE, NULL, NULL);
+ kfsb->file_monitor = g_file_monitor (kfsb->file, G_FILE_MONITOR_NONE, NULL, &error);
+ if (!kfsb->file_monitor)
+ {
+ g_warning ("Failed to create file monitor for %s: %s", g_file_peek_path (kfsb->file), error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ g_signal_connect (kfsb->file_monitor, "changed",
+ G_CALLBACK (file_changed), kfsb);
+ }
- compute_checksum (kfsb->digest, NULL, 0);
+ kfsb->dir_monitor = g_file_monitor (kfsb->dir, G_FILE_MONITOR_NONE, NULL, &error);
+ if (!kfsb->dir_monitor)
+ {
+ g_warning ("Failed to create file monitor for %s: %s", g_file_peek_path (kfsb->file), error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ g_signal_connect (kfsb->dir_monitor, "changed",
+ G_CALLBACK (dir_changed), kfsb);
+ }
- g_signal_connect (kfsb->file_monitor, "changed",
- G_CALLBACK (file_changed), kfsb);
- g_signal_connect (kfsb->dir_monitor, "changed",
- G_CALLBACK (dir_changed), kfsb);
+ compute_checksum (kfsb->digest, NULL, 0);
g_keyfile_settings_backend_keyfile_writable (kfsb);
g_keyfile_settings_backend_keyfile_reload (kfsb);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]