[PATCH v9 00/14] termios: support arbitrary baud rates on Linux, minor cleanups, alternative interface

H. Peter Anvin hpa@zytor.com
Thu Jun 12 01:35:31 GMT 2025


From: "H. Peter Anvin" (Intel) <hpa@zytor.com>

This is the arbitrary baud rates on Linux patchset, and the (proposed)
"explicitly true baudrate" interface proposed for future
standardization.

It also includes some generic cleanups to the best of my ability, and
removes USE_OLD_TTY from Hurd, which was the only remaining cause of
speed_t not being an actual baud rate.

A git tree is also available at:
https://git.zytor.com/linux/glibc/ branch hpa/termios9

Changes in v9:

- Refactor <termios_internals.h>, <kernel_termios.h> and
  <old_termios.h> to put all the internals termios
  architecture-specific stuff for both kernel and user space in a
  single place <termios_arch.h> and avoid using architecture #ifdefs
  in the common code. (Andreas Schwab)
- As the above change required opening up the "big patch" (v8 05/15)
  merge the pad clearing change (v8 06/15) back in (v9 05/14).
- Extend the speed field unification to Linux/Alpha, which has its own
  <termios-struct.h> which got missed. (Adhemerval Zanella)

Changes in v8:

- Clear the pad bytes in struct termios, but don't make them explicit,
  because alignment and therefore the number of padding bytes is
  different on m68k. (Adhemerval Zanella)
- Add array_foreach() and array_foreach_const() iterator macros
  to <array_length.h>.
- Use array_foreach_const() in the test case instead of open-coding
  array_length() and using a counter. (Adhemerval Zanella)
- Loop from 75 rather than 300 when doing the "standard baud rate
  series", mostly for clarity's sake.

Changes in v7: (special thanks to Adhemerval Zanella for reviews)

- Stylistic and typo fixes.
- Add missing copyright headers.
- Make the (already existing) padding field in struct termios explicit
  and make sure the full structure is initialized by tcgetattr(). This
  could help future expansion, and is just good practice.
  (Added as a separate patch in order to not invalidate previous
  reviews.)
- Consistently use __BOTHER rather than BOTHER.
- Simplify the test case by making better use of <support/check.h>
  macros. (Not quite as completely as Adhemerval had suggested, in
  order to get a little more information into certain error messages.)

Changes in v6: (special thanks to Adhemerval Zanella for bug reports)

- Fix the definition of CIBAUD on Alpha, and add explicit compile-time
  tests for CBAUD and CIBAUD validity.
- Fix the PowerPC build (stray <bits/sockios.h> remained, rather than
  <linux/sockios.h>.)
- Remove a spurious indentation change in <bits/termios-struct.h> on
  Linux.
- Separate the unification of the B constants and the updating of the
  manual into separate patches.
- Update the baud_t documentation to indicate that speed_t == baud_t
  is not going to be guaranteed in future versions, only that baud_t
  is a numeric type.

Changes in v5.2:

- tst-termios-linux: clean up the definition of the VERIFY and CHECK macros
- make sure sysdeps/unix/sysv/linux/Makefile is sorted to prevent lint error

Changes in v5:

- Added test for various combinations of the legacy and new interfaces.
- Fix several typos that caused major malfunctions, oops...
- Added Signed-off-bys for the Hurd patches.

Changes in v4:

- Using <linux/sockios.h> instead of a copied <bits/sockios.h>.
- __local_isatty() renamed __isatty_nostatus().
- Use *_CALL() versions of the SYSCALL macros.
- Fix USE_OLD_TTY removal on Hurd (missing #endif.)
- Fix speed_t being signed on Hurd (should be unsigned per POSIX.)
- Merge the speed_t constant definitions as they are now all identical.
- Use anonymous unions to support both __ispeed/__ospeed and
  c_ispeed/c_ospeed on all platforms, for consistency.
- All baud rate constants added to the manual.

Changes in v3:

- Fix improper use of tcsetattr() instead of __tcsetattr() in
  misc/getpass.c
- The .abilist files need to be sorted
- Move Hurd USE_OLD_TTY removal to before the *baud() interface patch

 NEWS                                               |   4 +
 bits/termios-baud.h                                |  72 +++
 bits/termios.h                                     |  54 +-
 include/array_length.h                             |  14 +
 include/termios.h                                  |  27 +-
 include/unistd.h                                   |   1 +
 io/Makefile                                        |   1 +
 io/isatty_nostatus.c                               |  29 +
 libio/filedoalloc.c                                |  12 +-
 login/openpty.c                                    |   2 +-
 manual/terminal.texi                               | 164 +++++-
 misc/getpass.c                                     |   4 +-
 sysdeps/mach/hurd/bits/ioctls.h                    |  31 +-
 sysdeps/mach/hurd/i386/libc.abilist                |   5 +
 sysdeps/mach/hurd/x86_64/libc.abilist              |   5 +
 sysdeps/unix/bsd/tcsetattr.c                       |   6 +-
 sysdeps/unix/sysv/linux/Makefile                   |   2 +-
 sysdeps/unix/sysv/linux/Versions                   |   7 +
 sysdeps/unix/sysv/linux/aarch64/libc.abilist       |  10 +
 .../unix/sysv/linux/alpha/bits/termios-c_cflag.h   |   2 +
 .../alpha/bits/{termios-baud.h => termios-cbaud.h} |  43 +-
 .../unix/sysv/linux/alpha/bits/termios-struct.h    |  11 +-
 sysdeps/unix/sysv/linux/alpha/kernel-features.h    |  11 +
 sysdeps/unix/sysv/linux/alpha/kernel_termios.h     |  43 --
 sysdeps/unix/sysv/linux/alpha/libc.abilist         |  10 +
 .../bits/termios-struct.h => alpha/termios_arch.h} |  26 +-
 sysdeps/unix/sysv/linux/arc/libc.abilist           |  10 +
 sysdeps/unix/sysv/linux/arm/be/libc.abilist        |  10 +
 sysdeps/unix/sysv/linux/arm/le/libc.abilist        |  10 +
 sysdeps/unix/sysv/linux/bits/ioctls.h              |  85 +--
 sysdeps/unix/sysv/linux/bits/termios-c_cflag.h     |   4 +-
 .../linux/bits/{termios-baud.h => termios-cbaud.h} |  41 +-
 sysdeps/unix/sysv/linux/bits/termios-struct.h      |  11 +-
 sysdeps/unix/sysv/linux/bits/termios.h             |  50 +-
 sysdeps/unix/sysv/linux/cfsetspeed.c               |  59 ++
 sysdeps/unix/sysv/linux/csky/libc.abilist          |  10 +
 sysdeps/unix/sysv/linux/hppa/libc.abilist          |  10 +
 sysdeps/unix/sysv/linux/i386/libc.abilist          |  10 +
 sysdeps/unix/sysv/linux/isatty.c                   |  28 +
 sysdeps/unix/sysv/linux/isatty_nostatus.c          |  26 +
 sysdeps/unix/sysv/linux/kernel-features.h          |   4 +
 .../unix/sysv/linux/loongarch/lp64/libc.abilist    |  10 +
 sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist |  10 +
 sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist   |  10 +
 sysdeps/unix/sysv/linux/microblaze/be/libc.abilist |  10 +
 sysdeps/unix/sysv/linux/microblaze/le/libc.abilist |  10 +
 sysdeps/unix/sysv/linux/mips/Versions              |   4 +
 .../unix/sysv/linux/mips/mips32/fpu/libc.abilist   |  12 +
 .../unix/sysv/linux/mips/mips32/nofpu/libc.abilist |  12 +
 .../unix/sysv/linux/mips/mips64/n32/libc.abilist   |  12 +
 .../unix/sysv/linux/mips/mips64/n64/libc.abilist   |  12 +
 .../{kernel_termios.h => mips/termios_arch.h}      |  39 +-
 sysdeps/unix/sysv/linux/old_termios.h              |  23 +
 sysdeps/unix/sysv/linux/or1k/libc.abilist          |  10 +
 sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h      |  36 ++
 .../unix/sysv/linux/powerpc/bits/termios-c_cflag.h |   4 +-
 .../bits/{termios-baud.h => termios-cbaud.h}       |  42 +-
 sysdeps/unix/sysv/linux/powerpc/kernel_termios.h   |  53 --
 .../sysv/linux/powerpc/powerpc32/fpu/libc.abilist  |  10 +
 .../linux/powerpc/powerpc32/nofpu/libc.abilist     |  10 +
 .../sysv/linux/powerpc/powerpc64/be/libc.abilist   |  10 +
 .../sysv/linux/powerpc/powerpc64/le/libc.abilist   |  10 +
 .../termios-struct.h => powerpc/termios_arch.h}    |  26 +-
 sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist    |  10 +
 sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist    |  10 +
 sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist  |  10 +
 sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist  |  10 +
 sysdeps/unix/sysv/linux/sh/be/libc.abilist         |  10 +
 sysdeps/unix/sysv/linux/sh/le/libc.abilist         |  10 +
 sysdeps/unix/sysv/linux/sparc/Versions             |   4 +
 .../sparc/bits/{termios-baud.h => termios-cbaud.h} |  39 +-
 sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist |  12 +
 sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist |  12 +
 .../kernel_termios.h => sparc/termios_arch.h}      |  41 +-
 sysdeps/unix/sysv/linux/speed.c                    | 363 +++++++++++--
 sysdeps/unix/sysv/linux/tcgetattr.c                |  86 ++-
 sysdeps/unix/sysv/linux/tcsetattr.c                | 125 +++--
 sysdeps/unix/sysv/linux/termios_arch.h             |  23 +
 sysdeps/unix/sysv/linux/termios_internals.h        | 143 +++++
 sysdeps/unix/sysv/linux/tst-termios-linux.c        | 592 +++++++++++++++++++++
 sysdeps/unix/sysv/linux/x86_64/64/libc.abilist     |  10 +
 sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist    |  10 +
 termios/Makefile                                   |   7 +-
 termios/Versions                                   |   4 +
 termios/baud.c                                     |  56 ++
 .../sparc/kernel_termios.h => termios/cfsetbaud.c  |  35 +-
 termios/cfsetspeed.c                               | 142 +----
 termios/speed.c                                    |  18 +-
 termios/sys/ttychars.h                             |   4 -
 termios/tcsetattr.c                                |   5 +-
 termios/termios.h                                  |  19 +-
 91 files changed, 2356 insertions(+), 793 deletions(-)


More information about the Libc-alpha mailing list