[glib] gunixmounts: Prevent "mounts-changed" race if /etc/mtab is used



commit 2db36d0d5cef9fb97861f79b1e97fa1c33f1ed59
Author: Ondrej Holy <oholy redhat com>
Date:   Mon Jul 17 15:53:24 2017 +0200

    gunixmounts: Prevent "mounts-changed" race if /etc/mtab is used
    
    The /etc/mtab file is still used by some distributions (e.g. Slackware),
    so it has to be monitored instead of /proc/self/mountinfo in order to
    avoid races between g_unix_mounts_get and "mounts-changed" signal. The
    util-linux is built with --enable-libmount-support-mtab in that case and
    mnt_has_regular_mtab is used for checks. Let's use mnt_has_regular_mtab
    also to determine which file to monitor.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779607

 gio/gunixmounts.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 2ccd9f7..2503fc0 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -550,7 +550,15 @@ get_mtab_monitor_file (void)
     return mountinfo_path;
 
 #ifdef HAVE_LIBMOUNT
-  /* If using libmount we'll have the logic in place to read mountinfo */
+  /* The mtab file is still used by some distros, so it has to be monitored in
+   * order to avoid races between g_unix_mounts_get and "mounts-changed" signal:
+   * https://bugzilla.gnome.org/show_bug.cgi?id=782814
+   */
+  if (mnt_has_regular_mtab (&mountinfo_path, NULL))
+    {
+      return mountinfo_path;
+    }
+
   if (stat (PROC_MOUNTINFO_PATH, &buf) == 0)
     {
       mountinfo_path = PROC_MOUNTINFO_PATH;


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