[+] fix exit status for commands

1. fix intercept_output when the process has died
    before select poll has been started;
This commit is contained in:
Siarhei Siniak 2024-12-04 20:28:20 +03:00
parent eb457950d3
commit a6cdf03523

@ -132,8 +132,11 @@ def intercept_output(
break
t2 = t1.poll(100)
if len(t2) == 1 and (t2[0][1] & select.POLLIN) > 0 and \
not (isinstance(last_data, bytes) and len(last_data) == 0):
if (
len(t2) == 1 and (t2[0][1] & select.POLLIN) > 0 and \
not (isinstance(last_data, bytes) and len(last_data) == 0) or
not current_subprocess.poll() is None
):
t3 = current_subprocess.stdout.peek()
t4: bytes = current_subprocess.stdout.read(len(t3))
@ -1557,6 +1560,12 @@ def pass_ssh_osx(argv):
last_chunk = chunk
break
assert not p.poll() is None
if p.poll() != 0:
logger.error(p.stderr.read())
sys.exit(p.poll())
assert not last_chunk is None
assert last_chunk['returncode'] == 0
@ -3844,7 +3853,7 @@ class Command(enum.StrEnum):
def commands_cli(
argv: Optional[list[str]] = None
) -> None:
) -> int:
if argv is None:
argv = sys.argv[1:]
@ -3933,14 +3942,14 @@ def commands_cli(
else:
raise NotImplementedError
except SystemExit:
pass
raise
except Exception:
msg = 'not implemented\n%s' % traceback.format_exc()
logging.error(msg)
if not msg is None:
custom_notify(msg=msg)
finally:
if not msg is None:
custom_notify(msg=msg)
if __name__ == '__main__':
commands_cli()
sys.exit(commands_cli())