oeqa/ssh: Further improve process exit handling

It looks like there were further cases where orphaned processes may be left
behind since the .kill() calls may be unsuccessful if the process terminated
due to the terminate or through normal exit. In that situation .wait()
wouldn't have been called.

Further tweak the exit code paths to ensure .wait() is called to update the
returncode value before returning in all cases.

(From OE-Core rev: 0a0a1731e38edfa72a141e8fd8f2de52be562e94)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2023-07-29 09:00:49 +01:00
parent de9508dbd3
commit c2d0ac3f0d

View File

@@ -265,7 +265,6 @@ def SSHCall(command, logger, timeout=None, **opts):
time.sleep(5) time.sleep(5)
try: try:
process.kill() process.kill()
process.wait()
except OSError: except OSError:
logger.debug('OSError when killing process') logger.debug('OSError when killing process')
pass pass
@@ -274,6 +273,7 @@ def SSHCall(command, logger, timeout=None, **opts):
" running time: %d seconds." % (timeout, endtime)) " running time: %d seconds." % (timeout, endtime))
logger.debug('Received data from SSH call:\n%s ' % lastline) logger.debug('Received data from SSH call:\n%s ' % lastline)
output += lastline output += lastline
process.wait()
else: else:
output_raw = process.communicate()[0] output_raw = process.communicate()[0]
@@ -288,10 +288,10 @@ def SSHCall(command, logger, timeout=None, **opts):
except TimeoutExpired: except TimeoutExpired:
try: try:
process.kill() process.kill()
process.wait()
except OSError: except OSError:
logger.debug('OSError') logger.debug('OSError')
pass pass
process.wait()
options = { options = {
"stdout": subprocess.PIPE, "stdout": subprocess.PIPE,
@@ -318,6 +318,7 @@ def SSHCall(command, logger, timeout=None, **opts):
# whilst running and ensure we don't leave a process behind. # whilst running and ensure we don't leave a process behind.
if process.poll() is None: if process.poll() is None:
process.kill() process.kill()
if process.returncode == None:
process.wait() process.wait()
logger.debug('Something went wrong, killing SSH process') logger.debug('Something went wrong, killing SSH process')
raise raise