diff options
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index d5330db13..e62f9d5cf 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -463,14 +463,17 @@ def process_running(pid_file): pid = f.read().strip() return pid_exists(int(pid)) -def process_named_running(name): +def process_named_running(name, cmdline: str=None): """ Checks if process with given name is running and returns its PID. If Process is not running, return None """ from psutil import process_iter - for p in process_iter(): - if name in p.name(): - return p.pid + for p in process_iter(['name', 'pid', 'cmdline']): + if cmdline: + if p.info['name'] == name and cmdline in p.info['cmdline']: + return p.info['pid'] + elif p.info['name'] == name: + return p.info['pid'] return None def is_list_equal(first: list, second: list) -> bool: @@ -1060,9 +1063,13 @@ def check_port_availability(ipaddress, port, protocol): if protocol == 'udp': server = UDPServer((ipaddress, port), None, bind_and_activate=True) server.server_close() - return True - except: - return False + except Exception as e: + # errno.h: + #define EADDRINUSE 98 /* Address already in use */ + if e.errno == 98: + return False + + return True def install_into_config(conf, config_paths, override_prompt=True): # Allows op-mode scripts to install values if called from an active config session |