From caf33a1f5d094d81004fc61d092cd735cd5623da Mon Sep 17 00:00:00 2001 From: Aaron Heise Date: Fri, 10 Feb 2023 21:39:05 -0600 Subject: [PATCH] fix issue with invalid fds sometimes --- rnsh/process.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rnsh/process.py b/rnsh/process.py index 4fcbea2..9edbe61 100644 --- a/rnsh/process.py +++ b/rnsh/process.py @@ -110,6 +110,8 @@ def tty_set_winsize(fd: int, rows: int, cols: int, h_pixels: int, v_pixels: int) :param h_pixels: number of visible horizontal pixels :param v_pixels: number of visible vertical pixels """ + if fd < 0: + return packed = struct.pack('HHHH', rows, cols, h_pixels, v_pixels) fcntl.ioctl(fd, termios.TIOCSWINSZ, packed) @@ -182,7 +184,7 @@ class CallbackSubprocess: self._log = module_logger.getChild(self.__class__.__name__) # self._log.debug(f"__init__({argv},{term},...") self._command: [str] = argv - self._env = env + self._env = env or {} self._loop = loop self._stdout_cb = stdout_callback self._terminated_cb = terminated_callback @@ -383,7 +385,11 @@ async def main(): # log.debug(f"terminated {rc}") retcode.set_result(rc) - process = CallbackSubprocess(sys.argv[1:], os.environ.get("TERM", "xterm"), loop, stdout, terminated) + process = CallbackSubprocess(argv=sys.argv[1:], + env={"TERM": os.environ.get("TERM", "xterm")}, + loop=loop, + stdout_callback=stdout, + terminated_callback=terminated) def sigint_handler(signal, frame): # log.debug("KeyboardInterrupt")