From 7d7300dd6dc163339ade4856cee1d31c8ec751b6 Mon Sep 17 00:00:00 2001 From: cedric lamoriniere Date: Thu, 28 Mar 2019 15:41:29 +0100 Subject: [PATCH] Fix corner case when /etc/mtab doesn't exist and procfs=/proc In some Linux configurations the `/etc/mtab` does not exist but the procfs_path is equal to `/proc`. With the fix done for the issue #1307, the described configuration didn't work. This Commit introduce an additional check that verifies if the `/etc/mtab` file exists before using it, else it defaults to `/self/mounts` Signed-off-by: cedric lamoriniere --- psutil/_pslinux.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 3502f1b14..fac9e781d 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1169,13 +1169,13 @@ def disk_partitions(all=False): fstypes.add("zfs") # See: https://github.com/giampaolo/psutil/issues/1307 - if procfs_path == "/proc": - mtab_path = os.path.realpath("/etc/mtab") + if procfs_path == "/proc" and os.path.isfile('/etc/mtab'): + mounts_path = os.path.realpath("/etc/mtab") else: - mtab_path = os.path.realpath("%s/self/mounts" % procfs_path) + mounts_path = os.path.realpath("%s/self/mounts" % procfs_path) retlist = [] - partitions = cext.disk_partitions(mtab_path) + partitions = cext.disk_partitions(mounts_path) for partition in partitions: device, mountpoint, fstype, opts = partition if device == 'none':