From 1c8700edfdb6a281d82f4db78782dc4c58bb4e94 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Wed, 10 Jan 2018 20:50:46 +0100 Subject: [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 --- sos/plugins/__init__.py | 19 ++++++++++++------- 1 file 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 -- cgit