Discussion:
[PATCH] Handle not being able to open /proc/<pid>/cmdline. Return "-" as netstat does when it doesn't know the command listening.
Jan-Frode Myklebust
2011-06-14 08:59:57 UTC
Permalink
---
func/minion/modules/portinfo.py | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/func/minion/modules/portinfo.py b/func/minion/modules/portinfo.py
index af94364..bfeb44b 100644
--- a/func/minion/modules/portinfo.py
+++ b/func/minion/modules/portinfo.py
@@ -14,7 +14,7 @@ import sub_process

class PortinfoModule(func_module.FuncModule):

- version = "0.0.2"
+ version = "0.0.3"
api_version = "0.0.1"
description = "Information on active network ports and processes listening."

@@ -57,5 +57,9 @@ class PortinfoModule(func_module.FuncModule):
"""
Returns the commandline for a given pid as a string.
"""
- proccmdline = open("/proc/" + pid + "/cmdline").readline().split('\x00')
- return " ".join(proccmdline)
+ try:
+ proccmdline = open("/proc/" + pid + "/cmdline").readline().split('\x00')
+ return " ".join(proccmdline)
+ except Exception, e:
+ # If we can't find the cmdline, return "-" as netstat would.
+ return "-"
--
1.7.1
Loading...