aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schuppert <mschuppert@redhat.com>2018-01-10 20:50:46 +0100
committerBryn M. Reeves <bmr@redhat.com>2018-04-17 15:40:10 +0100
commit1c8700edfdb6a281d82f4db78782dc4c58bb4e94 (patch)
treeebfb74640158d7cf622baa0d78f99b7de98f15a7
parent5d41100f9d289121467b436f124f91137bc7c621 (diff)
downloadsos-1c8700edfdb6a281d82f4db78782dc4c58bb4e94.tar.gz
[plugins] avoid callout when checking for running process
Replace the 'ps -ef' based Plugin.check_process_by_name() method with a native Python version that scans /proc/[0-9]*/cmdline instead. Resolves: #1186 Signed-off-by: Martin Schuppert mschuppe@redhat.com Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/plugins/__init__.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index c372c0f9..8f2abd41 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -1050,15 +1050,20 @@ class Plugin(object):
else:
return html
- def check_process_by_name(self, pr):
- """Checks if a named process is listed in ps -ef output."""
- ps = self.get_command_output("ps -ef")
+ def check_process_by_name(self, process):
+ """Checks if a named process is found in /proc/[0-9]*/cmdline.
+ Returns either True or False."""
status = False
- if ps['status'] == 0:
- for line in ps['output'].splitlines():
- if pr in line:
+ cmd_line_glob = "/proc/[0-9]*/cmdline"
+ try:
+ cmd_line_paths = glob.glob(cmd_line_glob)
+ for path in cmd_line_paths:
+ f = open(path, 'r')
+ cmd_line = f.read().strip()
+ if process in cmd_line:
status = True
- break
+ except IOError as e:
+ return False
return status