]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fallback to /proc/mounts.
authorOliver Kurth <okurth@vmware.com>
Mon, 3 Jun 2019 20:39:44 +0000 (13:39 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 3 Jun 2019 20:39:44 +0000 (13:39 -0700)
Use /proc/mounts on systems where /etc/mtab may not be there.
This change is targeted for guestInfo reporting at the moment.

open-vm-tools/lib/wiper/wiperPosix.c

index 68e75cf72708881cae31c007d97d8cf6c318363c..4326085a78edbf77383b7f2e3acd85950ba68956 100644 (file)
@@ -484,6 +484,50 @@ WiperPartitionFilter(WiperPartition *item,         // IN/OUT
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * WiperOpenMountFile --
+ *
+ *      Open mount file /etc/mtab or /proc/mounts.
+ *
+ * Results:
+ *      MNTHANDLE on success.
+ *      NULL on failure.
+ *
+ * Side Effects:
+ *      None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+static MNTHANDLE
+WiperOpenMountFile(void)
+{
+   MNTHANDLE fp;
+
+   fp = OPEN_MNTFILE("r");
+   if (fp == NULL) {
+#if defined(__linux__)
+#define PROC_MOUNTS     "/proc/mounts"
+      if (errno == ENOENT && strcmp(MNTFILE, PROC_MOUNTS) != 0) {
+         /*
+          * Try /proc/mounts if /etc/mtab is not available.
+          */
+         fp = Posix_Setmntent(PROC_MOUNTS, "r");
+         if (fp == NULL) {
+            Log("Could not open %s (%d)\n", PROC_MOUNTS, errno);
+         }
+         return fp;
+      }
+#endif
+      Log("Could not open %s (%d)\n", MNTFILE, errno);
+   }
+
+   return fp;
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -513,9 +557,8 @@ WiperSinglePartition_Open(const char *mountPoint,      // IN
 
    ASSERT(initDone);
 
-   fp = OPEN_MNTFILE("r");
+   fp = WiperOpenMountFile();
    if (fp == NULL) {
-      Log("Could not open %s\n", MNTFILE);
       return NULL;
    }
 
@@ -666,10 +709,9 @@ WiperPartition_Open(WiperPartition_List *pl,
 
    DblLnkLst_Init(&pl->link);
 
-   /* Basically call functions to parse /etc/mtab ... */
-   fp = OPEN_MNTFILE("r");
+   /* Basically call functions to parse mounts table */
+   fp = WiperOpenMountFile();
    if (fp == NULL) {
-      Log("Unable to open mount file.\n");
       return FALSE;
    }