summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Lamoriniere <cedric.lamoriniere@gmail.com>2019-03-28 16:46:18 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2019-03-28 16:46:18 +0100
commit9691d791d7a00c7e4055156545941f4ccfa2ee12 (patch)
treeeecb6f43eb765e098f293f5ad318ba42488c4ad2
parent05338fb0e67cb087844fdc1a10e0d4bb0617aba2 (diff)
downloadpsutil-9691d791d7a00c7e4055156545941f4ccfa2ee12.tar.gz
Fix corner case when /etc/mtab doesn't exist and procfs=/proc (#1470)
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 `<procfs_path>/self/mounts` Signed-off-by: cedric lamoriniere <cedric.lamoriniere@datadoghq.com>
-rw-r--r--psutil/_pslinux.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 3502f1b1..fac9e781 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':