3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-21 22:09:23 +01:00

test-runner: make is_process_running more accurate

This function was checking if the process object exists, which can
persist long after a process is killed, or dies unexpectedly. Check
that the actual PID exists by sending signal 0.
This commit is contained in:
James Prestwood 2022-06-24 16:07:35 -07:00 committed by Denis Kenzior
parent c10ade711d
commit 3e5ce99e82

View File

@ -342,10 +342,24 @@ class Namespace:
def stop_process(self, p, force=False):
p.kill(force)
def _is_running(self, pid):
try:
os.kill(pid, 0)
except OSError:
return False
return True
def is_process_running(self, process):
for p in Process.get_all():
if p.namespace == self.name and p.args[0] == process:
return True
# Namespace processes are actually started by 'ip' where
# the actual process name is at index 4 of the arguments.
idx = 0 if not p.namespace else 4
if p.namespace == self.name and p.args[idx] == process:
# The process object exists, but make sure its
# actually running.
return self._is_running(p.pid)
return False
def _cleanup_dbus(self):