Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 4ad85fb

Browse files
committed
Kill qemu properly if communication fails
During the first communication with qemu, we are currently catching the wrong exception in case of error, causing application to remain a zombie process. This patch will fix the problem. Signed-off-by: Andrea Cervesato <[email protected]> Tested-by: Cyril Hrubis <[email protected]>
1 parent 99f7e92 commit 4ad85fb

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

ltp/qemu.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def stop(
385385

386386
self._write_stdin("poweroff\n")
387387

388-
while self._proc.poll() is None:
388+
while self.is_running:
389389
events = self._poller.poll(1)
390390
for fdesc, _ in events:
391391
if fdesc != self._proc.stdout.fileno():
@@ -400,7 +400,7 @@ def stop(
400400
pass
401401

402402
# still running -> stop process
403-
if self._proc.poll() is None:
403+
if self.is_running:
404404
self._logger.info("Killing virtual machine process")
405405

406406
self._proc.send_signal(signal.SIGHUP)
@@ -411,7 +411,7 @@ def stop(
411411
timer.check(err_msg="Timed out during stop")
412412

413413
# wait for process to end
414-
while self._proc.poll() is None:
414+
while self.is_running:
415415
time.sleep(1e-6)
416416
timer.check(err_msg="Timed out during stop")
417417

@@ -431,7 +431,7 @@ def force_stop(
431431
with Timeout(timeout) as timer:
432432
try:
433433
# still running -> stop process
434-
if self._proc.poll() is None:
434+
if self.is_running:
435435
self._logger.info("Killing virtual machine process")
436436

437437
self._proc.send_signal(signal.SIGKILL)
@@ -447,7 +447,7 @@ def force_stop(
447447
timer.check(err_msg="Timed out during stop")
448448

449449
# wait for process to end
450-
while self._proc.poll() is None:
450+
while self.is_running:
451451
time.sleep(1e-6)
452452
timer.check(err_msg="Timed out during stop")
453453
finally:
@@ -463,6 +463,8 @@ def communicate(
463463
if self.is_running:
464464
raise SUTError("Virtual machine is already running")
465465

466+
error = None
467+
466468
with self._comm_lock:
467469
self._logged_in = False
468470

@@ -531,13 +533,15 @@ def communicate(
531533

532534
self._logger.info("Virtual machine started")
533535
except SUTError as err:
534-
if not self._stop:
535-
if self._proc and self._proc.poll() is not None:
536-
# this can happen when shell is available but
537-
# something happened during commands execution
538-
self._proc.kill()
536+
error = err
537+
538+
if not self._stop and error:
539+
if self.is_running:
540+
# this can happen when shell is available but
541+
# something happened during commands execution
542+
self.stop(iobuffer=iobuffer)
539543

540-
raise SUTError(err)
544+
raise SUTError(error)
541545

542546
def run_command(
543547
self,

ltp/sut.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class SUTError(LTPException):
1515
"""
1616

1717

18-
class SUTTimeoutError(LTPException):
18+
class SUTTimeoutError(SUTError):
1919
"""
2020
Raised when timeout error occurs in SUT.
2121
"""
2222

2323

24-
class KernelPanicError(LTPException):
24+
class KernelPanicError(SUTError):
2525
"""
2626
Raised during kernel panic.
2727
"""

0 commit comments

Comments
 (0)