Skip to content

Commit

Permalink
fix #1014: Linux can mask legitimate ENOENT exceptions as NoSuchProcess.
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Apr 21, 2017
1 parent b303690 commit 22651a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
9 changes: 9 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*

*XXXX-XX-XX*

5.2.3
=====

**Bug fixes**

- 1014_: Linux can mask legitimate ENOENT exceptions as NoSuchProcess.

*2017-04-10*

5.2.2
Expand Down
2 changes: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
]
__all__.extend(_psplatform.__extra__all__)
__author__ = "Giampaolo Rodola'"
__version__ = "5.2.2"
__version__ = "5.2.3"
version_info = tuple([int(num) for num in __version__.split('.')])
AF_LINK = _psplatform.AF_LINK
POWER_TIME_UNLIMITED = _common.POWER_TIME_UNLIMITED
Expand Down
19 changes: 13 additions & 6 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,9 @@ def pids():


def pid_exists(pid):
"""Check for the existence of a unix PID."""
"""Check for the existence of a unix PID. Linux TIDs are not
supported (always return False).
"""
if not _psposix.pid_exists(pid):
return False
else:
Expand Down Expand Up @@ -1333,13 +1335,18 @@ def wrapper(self, *args, **kwargs):
try:
return fun(self, *args, **kwargs)
except EnvironmentError as err:
# ENOENT (no such file or directory) gets raised on open().
# ESRCH (no such process) can get raised on read() if
# process is gone in meantime.
if err.errno in (errno.ENOENT, errno.ESRCH):
raise NoSuchProcess(self.pid, self._name)
if err.errno in (errno.EPERM, errno.EACCES):
raise AccessDenied(self.pid, self._name)
# ESRCH (no such process) can be raised on read() if
# process is gone in the meantime.
if err.errno == errno.ESRCH:
raise NoSuchProcess(self.pid, self._name)
# ENOENT (no such file or directory) can be raised on open().
if err.errno == errno.ENOENT and not os.path.exists("%s/%s" % (
self._procfs_path, self.pid)):
raise NoSuchProcess(self.pid, self._name)
# Note: zombies will keep existing under /proc until they're
# gone so there's no way to distinguish them in here.
raise
return wrapper

Expand Down

0 comments on commit 22651a6

Please sign in to comment.