[glib/wip/msanchez/libmount: 8/8] Monitor /proc/self/mountinfo when using libmount
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/msanchez/libmount: 8/8] Monitor /proc/self/mountinfo when using libmount
- Date: Fri, 20 May 2016 16:33:52 +0000 (UTC)
commit 2d900d46f54aed2931fe3a24bf70d77b1bdfb510
Author: Mario Sanchez Prada <mario endlessm com>
Date: Fri May 20 16:59:02 2016 +0100
Monitor /proc/self/mountinfo when using libmount
gio/gunixmounts.c | 54 ++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 39 insertions(+), 15 deletions(-)
---
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 9233635..c480065 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);
@@ -445,20 +450,6 @@ get_mtab_read_file (void)
#endif
}
-static char *
-get_mtab_monitor_file (void)
-{
-#ifdef _PATH_MOUNTED
-# ifdef __linux__
- return "/proc/mounts";
-# else
- return _PATH_MOUNTED;
-# endif
-#else
- return "/etc/mtab";
-#endif
-}
-
#ifndef HAVE_GETMNTENT_R
G_LOCK_DEFINE_STATIC(getmntent);
#endif
@@ -546,6 +537,39 @@ _g_get_unix_mounts (void)
#endif // HAVE_LIBMOUNT
+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__
+ mountinfo_path = "/proc/mounts";
+# else
+ mountinfo_path = _PATH_MOUNTED;
+# endif
+#else
+ mountinfo_path = "/etc/mtab";
+#endif
+
+ return mountinfo_path;
+}
+
/* mnttab.h {{{2 */
#elif defined (HAVE_SYS_MNTTAB_H)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]