service: fix service alive checking

This change the way we check for service being alive in a more portable
way by using os.kill() with a null signal.

Change-Id: I588ab19de15b351c1de3ab28b8655e400b2a2064
This commit is contained in:
Julien Danjou 2013-12-11 18:44:05 +01:00
parent 536e04848b
commit 69532196a1

View File

@ -109,13 +109,10 @@ class ServiceRestartTest(base.BaseTestCase):
@staticmethod @staticmethod
def _check_process_alive(pid): def _check_process_alive(pid):
try: try:
with open("/proc/%d/status" % pid) as fd_proc: os.kill(pid, 0)
for line in fd_proc.readlines(): except OSError:
if line.startswith("State:"):
state = line.split(":", 1)[1].strip().split(' ')[0]
return state not in ['Z', 'T', 'Z+']
except IOError:
return False return False
return True
def check_process_alive(self): def check_process_alive(self):
cond = lambda: self._check_process_alive(self.sub.pid) cond = lambda: self._check_process_alive(self.sub.pid)