flashtool: usb bootloader request fix

Open the usb device with the O_NOCTTY flag.  This prevents
a SIGHUP signal from killing the flashtool process if the
bootloader request results in a hangup event.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2025-03-15 16:37:50 -04:00
parent b734c57d3e
commit 418b43b0fa

View File

@ -959,16 +959,13 @@ class SerialSocket(BaseSocket):
start_usb_id = usb_info["usb_id"] start_usb_id = usb_info["usb_id"]
fd: Optional[int] = None fd: Optional[int] = None
with contextlib.suppress(OSError): with contextlib.suppress(OSError):
fd = os.open(str(device), os.O_RDWR) fd = os.open(str(device), os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
fcntl.ioctl( dtr_data = struct.pack('I', termios.TIOCM_DTR)
fd, termios.TIOCMBIS, struct.pack('I', termios.TIOCM_DTR) fcntl.ioctl(fd, termios.TIOCMBIS, dtr_data)
)
t = termios.tcgetattr(fd) t = termios.tcgetattr(fd)
t[4] = t[5] = termios.B1200 t[4] = t[5] = termios.B1200
termios.tcsetattr(fd, termios.TCSANOW, t) termios.tcsetattr(fd, termios.TCSANOW, t)
fcntl.ioctl( fcntl.ioctl(fd, termios.TIOCMBIC, dtr_data)
fd, termios.TIOCMBIC, struct.pack('I', termios.TIOCM_DTR)
)
if fd is not None: if fd is not None:
os.close(fd) os.close(fd)
output("Waiting for USB Reconnect.") output("Waiting for USB Reconnect.")