From ab3edfd8a9f89a80f2ff0e89aab64c0acb70abe0 Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 14 Jul 2026 23:38:49 -0700 Subject: [PATCH] Fix 2 Mbaud serial configuration on Linux DrawBridge configures its serial connection at 2,000,000 baud. The Unix fallback passed that numeric value directly to cfsetspeed(). Raw baud values are not portable speed_t values. musl rejects them, and binaries linked to cfsetspeed@GLIBC_2.2.5 can receive EINVAL when run with newer glibc termios compatibility code. Translate 2000000 to B2000000 before calling cfsetspeed(), and fail cleanly on platforms that do not provide that constant. --- floppybridge/SerialIO.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/floppybridge/SerialIO.cpp b/floppybridge/SerialIO.cpp index 5256420..f84ecb1 100644 --- a/floppybridge/SerialIO.cpp +++ b/floppybridge/SerialIO.cpp @@ -673,9 +673,18 @@ SerialIO::Response SerialIO::configurePort(const Configuration& configuration) { term.c_ospeed = configuration.baudRate; if (ioctl(m_portHandle, TCSETS2, &term) < 0) return Response::rUnknownError; #else + // Passing raw numeric baud rates to cfsetspeed() is non-portable across + // libc implementations and glibc ABIs. Use Linux's B2000000 explicitly. + if (baud == 2000000) { +#ifdef B2000000 + baud = B2000000; +#else + return Response::rUnknownError; +#endif + } term.c_cflag &= ~CBAUD; term.c_cflag |= CBAUDEX; - if (cfsetspeed(&term, baud) < 0) return Response::rUnknownError; + if (cfsetspeed(&term, static_cast(baud)) < 0) return Response::rUnknownError; #endif } #endif