[glib/wip/msanchez/libmount: 129/129] Monitor /proc/self/mountinfo when using libmount



commit cc5a9009544b6b1d00d2187249cd66e641e92e69
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Fri May 20 16:59:02 2016 +0100

    Monitor /proc/self/mountinfo when using libmount
    
    https://bugzilla.gnome.org/show_bug.cgi?id=522053

 gio/gunixmounts.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 8de44b5..e111788 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -375,6 +375,11 @@ create_unix_mount_point (const char *device_path,
 
 #ifdef HAVE_LIBMOUNT
 
+/* For documentation on /proc/self/mountinfo see
+ * http://www.kernel.org/doc/Documentation/filesystems/proc.txt
+ */
+#define PROC_MOUNTINFO_PATH "/proc/self/mountinfo"
+
 static GList *
 _g_get_unix_mounts (void)
 {
@@ -386,7 +391,7 @@ _g_get_unix_mounts (void)
   GList *return_list = NULL;
 
   ctxt = mnt_new_context ();
-  mnt_context_get_table (ctxt, "/proc/self/mountinfo", &table);
+  mnt_context_get_table (ctxt, PROC_MOUNTINFO_PATH, &table);
   if (!table)
     mnt_context_get_mtab (ctxt, &table);
 
@@ -537,15 +542,34 @@ _g_get_unix_mounts (void)
 static char *
 get_mtab_monitor_file (void)
 {
+  static char *mountinfo_path = NULL;
+#ifdef HAVE_LIBMOUNT
+  struct stat buf;
+#endif
+
+  if (mountinfo_path != NULL)
+    return mountinfo_path;
+
+#ifdef HAVE_LIBMOUNT
+  /* If using libmount we'll have the logic in place to read mountinfo */
+  if (stat (PROC_MOUNTINFO_PATH, &buf) == 0)
+    {
+      mountinfo_path = PROC_MOUNTINFO_PATH;
+      return mountinfo_path;
+    }
+#endif
+
 #ifdef _PATH_MOUNTED
 # ifdef __linux__
-  return "/proc/mounts";
+  mountinfo_path = "/proc/mounts";
 # else
-  return _PATH_MOUNTED;
+  mountinfo_path = _PATH_MOUNTED;
 # endif
 #else
-  return "/etc/mtab";
+  mountinfo_path = "/etc/mtab";
 #endif
+
+  return mountinfo_path;
 }
 
 /* mnttab.h {{{2 */


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