Fix issue with running rnsh without proper tty (like from launch)

This commit is contained in:
Aaron Heise 2023-02-12 01:51:58 -06:00
parent 14b718d88e
commit 2e61b70996

View File

@ -184,7 +184,9 @@ class TTYRestorer(contextlib.AbstractContextManager):
:param fd: file descriptor of tty
"""
self._fd = fd
self._tattr = termios.tcgetattr(self._fd)
self._tattr = None
with contextlib.suppress(termios.error):
termios.tcgetattr(self._fd)
def raw(self):
"""
@ -210,12 +212,13 @@ class TTYRestorer(contextlib.AbstractContextManager):
"""
Restore termios settings to state captured in constructor.
"""
termios.tcsetattr(self._fd, termios.TCSADRAIN, self._tattr)
self.set_attr(self._tattr, termios.TCSADRAIN)
def __exit__(self, __exc_type: typing.Type[BaseException], __exc_value: BaseException,
__traceback: types.TracebackType) -> bool:
self.restore()
return False
with contextlib.suppress(termios.error):
self.restore()
return __exc_type is not None and issubclass(__exc_type, termios.error)
async def event_wait(evt: asyncio.Event, timeout: float) -> bool: