Skip to content

Commit

Permalink
fix #632: [Linux] better error message if cannot parse process UNIX c…
Browse files Browse the repository at this point in the history
…onnections.
  • Loading branch information
giampaolo committed Jun 17, 2015
1 parent 7ae00aa commit 17325ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Bug tracker at https://github.com/giampaolo/psutil/issues

3.0.0 - XXXX-XX-XX
3.0.1 - XXXX-XX-XX
==================

**Bug fixes**

- #632: [Linux] better error message if cannot parse process UNIX connections.


3.0.0 - 2015-06-13
==================

**Enhancements**
Expand Down
16 changes: 13 additions & 3 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,13 @@ def process_inet(self, file, family, type_, inodes, filter_pid=None):
with open(file, 'rt') as f:
f.readline() # skip the first line
for line in f:
_, laddr, raddr, status, _, _, _, _, _, inode = \
line.split()[:10]
try:
_, laddr, raddr, status, _, _, _, _, _, inode = \
line.split()[:10]
except ValueError:
raise RuntimeError(
"error while parsing %s; malformed line %r" % (
file, line))
if inode in inodes:
# # We assume inet sockets are unique, so we error
# # out if there are multiple references to the
Expand Down Expand Up @@ -495,7 +500,12 @@ def process_unix(self, file, family, inodes, filter_pid=None):
f.readline() # skip the first line
for line in f:
tokens = line.split()
_, _, _, _, type_, _, inode = tokens[0:7]
try:
_, _, _, _, type_, _, inode = tokens[0:7]
except ValueError:
raise RuntimeError(
"error while parsing %s; malformed line %r" % (
file, line))
if inode in inodes:
# With UNIX sockets we can have a single inode
# referencing many file descriptors.
Expand Down
2 changes: 2 additions & 0 deletions test/test_psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,8 @@ def test_prog_w_funky_name(self):
subprocess.check_call(["gcc", c_file, "-o", funky_name])
sproc = get_test_subprocess([funky_name, "arg1", "arg2"])
p = psutil.Process(sproc.pid)
# ...in order to try to prevent occasional failures on travis
wait_for_pid(p.pid)
self.assertEqual(p.name(), "foo bar )")
self.assertEqual(p.exe(), "/tmp/foo bar )")
self.assertEqual(p.cmdline(), ["/tmp/foo bar )", "arg1", "arg2"])
Expand Down

0 comments on commit 17325ef

Please sign in to comment.