I added graceful parameter to kill_command. When it is set to True the slave first tries to interrupt the command using SIG_INT. Then it waits 5 seconds and checks if the process is still alive using pid_exists(). When the command does not terminate after this period it is killed by SIG_KILL.
This is basically needed if we want to keep the output of a command that timeouts. When killed (not interrupted) the command's output is lost and never logged.
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Slave/NetTestSlave.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py index 3b8bf79..057deea 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -439,11 +439,29 @@ class SlaveMethods:
return res
- def kill_command(self, id): + def kill_command(self, id, graceful=False): cmd = self._command_context.get_cmd(id) if cmd is not None: if not cmd.get_result_sent(): - cmd.kill(None) + if graceful: + check=0 + cmd.set_gracefully_killed() + cmd.interrupt(None) + while check < 5: + sleep(1) + if not cmd.pid_exists(): + break + check += 1 + + if cmd.pid_exists(): + logging.debug("Graceful termination timeout, killing") + cmd.kill(None) + else: + return None + else: + cmd.set_gracefully_killed(False) + cmd.kill(None) + result = cmd.get_result() cmd.set_result_sent() return result