From ed24edd7c8fc40ed9fbfc5bde14dbd76070d8ed1 Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Fri, 19 Apr 2024 09:54:50 +0200 Subject: [PATCH] gunixmounts: Use fallback if libmount monitoring fails The recently added libmount-based unix mount monitoring may fail when the device exceeds inotify limits. Let's fallback to the older implementation in case of the `mnt_monitor_get_fd` function failure. This among others fixes tracker-miners failures caused by seccomp rules. Fixes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/315 --- gio/gunixmounts.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c index a7a9363cb..6df984420 100644 --- a/gio/gunixmounts.c +++ b/gio/gunixmounts.c @@ -155,7 +155,7 @@ G_LOCK_DEFINE_STATIC (proc_mounts_source); /* Protected by proc_mounts_source lock */ static guint64 mount_poller_time = 0; -static GSource *proc_mounts_watch_source; +static GSource *proc_mounts_watch_source = NULL; #ifdef HAVE_SYS_MNTTAB_H #define MNTOPT_RO "ro" @@ -1921,11 +1921,10 @@ proc_mounts_changed (GIOChannel *channel, } G_UNLOCK (proc_mounts_source); } +#endif -#else if (cond & G_IO_ERR) has_changed = TRUE; -#endif if (has_changed) { @@ -2066,14 +2065,20 @@ mount_monitor_start (void) } else { - g_set_error_literal (&error, G_IO_ERROR, g_io_error_from_errno (-ret), - g_strerror (-ret)); + g_debug ("mnt_monitor_get_fd failed: %s", g_strerror (-ret)); + g_clear_pointer (&proc_mounts_monitor, mnt_unref_monitor); + + /* The mnt_monitor_get_fd function failed e.g. inotify limits are + * exceeded. Let's try to silently fallback to the old behavior. + * See: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/315 + */ } G_UNLOCK (proc_mounts_source); -#else - proc_mounts_channel = g_io_channel_new_file (mtab_path, "r", &error); #endif + if (proc_mounts_channel == NULL) + proc_mounts_channel = g_io_channel_new_file (mtab_path, "r", &error); + if (proc_mounts_channel == NULL) { g_warning ("Error creating IO channel for %s: %s (%s, %d)", mtab_path, @@ -2085,10 +2090,12 @@ mount_monitor_start (void) G_LOCK (proc_mounts_source); #ifdef HAVE_LIBMOUNT - proc_mounts_watch_source = g_io_create_watch (proc_mounts_channel, G_IO_IN); -#else - proc_mounts_watch_source = g_io_create_watch (proc_mounts_channel, G_IO_ERR); + if (proc_mounts_monitor != NULL) + proc_mounts_watch_source = g_io_create_watch (proc_mounts_channel, G_IO_IN); #endif + if (proc_mounts_watch_source == NULL) + proc_mounts_watch_source = g_io_create_watch (proc_mounts_channel, G_IO_ERR); + mount_poller_time = (guint64) g_get_monotonic_time (); g_source_set_callback (proc_mounts_watch_source, (GSourceFunc) proc_mounts_changed,