summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-06-17 11:50:46 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2015-06-17 11:50:46 +0200
commit17325efdd1b500870f58e794b7c2e02bf3516c78 (patch)
tree80d6aa42277e529ba65564f458228792b0cab9b0
parent7ae00aaca9e432147071a076b4bc4ea6e40e69a3 (diff)
downloadpsutil-17325efdd1b500870f58e794b7c2e02bf3516c78.tar.gz
fix #632: [Linux] better error message if cannot parse process UNIX connections.
-rw-r--r--HISTORY.rst10
-rw-r--r--psutil/_pslinux.py16
-rw-r--r--test/test_psutil.py2
3 files changed, 24 insertions, 4 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 8c026524..4793d3d3 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -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**
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 668154bb..db96776a 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -466,8 +466,13 @@ class Connections:
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
@@ -495,7 +500,12 @@ class Connections:
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.
diff --git a/test/test_psutil.py b/test/test_psutil.py
index 66209ead..50749c46 100644
--- a/test/test_psutil.py
+++ b/test/test_psutil.py
@@ -1560,6 +1560,8 @@ class TestProcess(unittest.TestCase):
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"])