Skip to content

Commit

Permalink
Fix corner case when /etc/mtab doesn't exist and procfs=/proc (#1470)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
clamoriniere authored and giampaolo committed Mar 28, 2019
1 parent 05338fb commit 9691d79
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 9691d79

Please sign in to comment.