From: Oliver Kurth Date: Mon, 3 Jun 2019 20:39:44 +0000 (-0700) Subject: Fallback to /proc/mounts. X-Git-Tag: stable-11.0.0~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19969734d2a64e52cccf8f04669b55ad13f9c61c;p=thirdparty%2Fopen-vm-tools.git Fallback to /proc/mounts. Use /proc/mounts on systems where /etc/mtab may not be there. This change is targeted for guestInfo reporting at the moment. --- diff --git a/open-vm-tools/lib/wiper/wiperPosix.c b/open-vm-tools/lib/wiper/wiperPosix.c index 68e75cf72..4326085a7 100644 --- a/open-vm-tools/lib/wiper/wiperPosix.c +++ b/open-vm-tools/lib/wiper/wiperPosix.c @@ -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; }