diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-06-20 14:39:42 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-06-20 14:39:42 +0200 |
commit | 9ad8e1416dfc579de0fec640dd3ea015ebb3e7cb (patch) | |
tree | e59d141859b7f0ac7f915ddbad464a8a9828a270 | |
parent | b6e452b51f661babf4889b9d4b9e3537d273799f (diff) | |
download | psutil-9ad8e1416dfc579de0fec640dd3ea015ebb3e7cb.tar.gz |
(linux / net connections) do not swallow all OSError exceptions
-rw-r--r-- | HISTORY.rst | 3 | ||||
-rw-r--r-- | psutil/_pslinux.py | 14 |
2 files changed, 13 insertions, 4 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index 4a277c08..9b86c6e8 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,7 +9,8 @@ Bug tracker at https://github.com/giampaolo/psutil/issues - #634: [Linux] Proces.cmdline() does not include empty string arguments. - #635: [UNIX] crash on module import if 'enum' package is installed on python < 3.4. - +- #636: [Linux] *connections functions may swallow errors and return an + incomplete list of connnections. 3.0.0 - 2015-06-13 ================== diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 6c84faf2..3f2d802c 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -383,9 +383,17 @@ class Connections: for fd in os.listdir("/proc/%s/fd" % pid): try: inode = os.readlink("/proc/%s/fd/%s" % (pid, fd)) - except OSError: - # TODO: need comment here - continue + except OSError as err: + # ENOENT == file which is gone in the meantime; + # os.stat('/proc/%s' % self.pid) will be done later + # to force NSP (if it's the case) + if err.errno in (errno.ENOENT, errno.ESRCH): + continue + elif err.errno == errno.EINVAL: + # not a link + continue + else: + raise else: if inode.startswith('socket:['): # the process is using a socket |