summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-01-03 14:49:02 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2015-01-03 14:49:02 +0100
commit18230b9a3e59262655dce918193023772471061b (patch)
treeae61f7e3bd285f08bef5f6d400c03b593f323b13
parentad2624ae1679e884087f448df8c1aedbaf3d346d (diff)
downloadpsutil-18230b9a3e59262655dce918193023772471061b.tar.gz
fix #571: [Linux] Process.open_files() might swallow AccessDenied exceptions
-rw-r--r--HISTORY.rst2
-rw-r--r--psutil/_pslinux.py35
2 files changed, 21 insertions, 16 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 56539ac7..e74fbdb7 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -24,6 +24,8 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
- #567: [Linux] in the alternative implementation of CPU affinity PyList_Append
and Py_BuildValue return values are not checked.
- #569: [FreeBSD] fix memory leak in psutil.cpu_count(logical=False).
+- #571: [Linux] Process.open_files() might swallow AccessDenied exceptions and
+ return an incomplete list of open files.
2.1.3 - 2014-09-26
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 8ffff23d..3bf062b1 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1032,23 +1032,26 @@ class Process(object):
hit_enoent = False
for fd in files:
file = "/proc/%s/fd/%s" % (self.pid, fd)
- if os.path.islink(file):
- try:
- file = os.readlink(file)
- except OSError as err:
- # ENOENT == file which is gone in the meantime
- if err.errno in (errno.ENOENT, errno.ESRCH):
- hit_enoent = True
- continue
- raise
+ try:
+ file = os.readlink(file)
+ except OSError as err:
+ # ENOENT == file which is gone in the meantime
+ if err.errno in (errno.ENOENT, errno.ESRCH):
+ hit_enoent = True
+ continue
+ elif err.errno == errno.EINVAL:
+ # not a link
+ continue
else:
- # If file is not an absolute path there's no way
- # to tell whether it's a regular file or not,
- # so we skip it. A regular file is always supposed
- # to be absolutized though.
- if file.startswith('/') and isfile_strict(file):
- ntuple = _common.popenfile(file, int(fd))
- retlist.append(ntuple)
+ raise
+ else:
+ # If file is not an absolute path there's no way
+ # to tell whether it's a regular file or not,
+ # so we skip it. A regular file is always supposed
+ # to be absolutized though.
+ if file.startswith('/') and isfile_strict(file):
+ ntuple = _common.popenfile(file, int(fd))
+ retlist.append(ntuple)
if hit_enoent:
# raise NSP if the process disappeared on us
os.stat('/proc/%s' % self.pid)