Skip to content

{bp-19184} drivers/serial: add job-control TTY ioctls and libc wrappers - #19708

Merged
xiaoxiang781216 merged 1 commit into
apache:releases/13.0from
jerpelea:bp-19184
Aug 6, 2026
Merged

{bp-19184} drivers/serial: add job-control TTY ioctls and libc wrappers#19708
xiaoxiang781216 merged 1 commit into
apache:releases/13.0from
jerpelea:bp-19184

Conversation

@jerpelea

@jerpelea jerpelea commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

NuttX has no real session/process-group abstraction, so the TTY layer collapses the foreground process group onto the single dev->pid field (pgrp == pid, one member per group). Extend the controlling-terminal support so portable software (e.g. dropbear, socat) that relies on job-control primitives works without losing the existing NuttX-specific behaviour.

Driver (serial.c, pty.c):

  • TIOCSCTTY now accepts a flag: arg > 0 keeps the historical "target PID in arg" semantics (NSH registers the foreground command it just spawned), while arg == 0 selects the calling task via nxsched_getpid(), matching the POSIX flag convention used by dropbear/socat/apue. This preserves all existing callers and makes the previously-dead arg==0 path deliver SIGINT correctly.
  • Add TIOCGPGRP/TIOCGSID (return dev->pid) and TIOCSPGRP (set it).
  • pty.c gains the same handlers against pd_pid and includes nuttx/sched.h for nxsched_getpid().

ioctl numbers (tioctl.h): TIOCGPGRP/TIOCSPGRP/TIOCGSID at 0x37-0x39.

libc wrappers:

  • termios: tcgetpgrp(), tcsetpgrp(), tcgetsid() over the new ioctls.
  • unistd: setsid()/getsid()/setpgid() stubs consistent with the existing getpgrp()/getpgid() single-session model (sid == pgid == pid; setpgid only succeeds for pgid == pid).

Declare the new prototypes in unistd.h (tcgetsid was already in termios.h) and register all sources in the Make.defs/CMakeLists.

Group-broadcast signalling (kill(-pgrp)) remains unsupported, so tty signals still target the single dev->pid; a real session/process group model is left as a follow-up.

Impact

RELEASE

Testing

CI

NuttX has no real session/process-group abstraction, so the TTY layer
collapses the foreground process group onto the single dev->pid field
(pgrp == pid, one member per group).  Extend the controlling-terminal
support so portable software (e.g. dropbear, socat) that relies on
job-control primitives works without losing the existing NuttX-specific
behaviour.

Driver (serial.c, pty.c):
- TIOCSCTTY now accepts a flag: arg > 0 keeps the historical "target
  PID in arg" semantics (NSH registers the foreground command it just
  spawned), while arg == 0 selects the calling task via
  nxsched_getpid(), matching the POSIX flag convention used by
  dropbear/socat/apue.  This preserves all existing callers and makes
  the previously-dead arg==0 path deliver SIGINT correctly.
- Add TIOCGPGRP/TIOCGSID (return dev->pid) and TIOCSPGRP (set it).
- pty.c gains the same handlers against pd_pid and includes
  nuttx/sched.h for nxsched_getpid().

ioctl numbers (tioctl.h): TIOCGPGRP/TIOCSPGRP/TIOCGSID at 0x37-0x39.

libc wrappers:
- termios: tcgetpgrp(), tcsetpgrp(), tcgetsid() over the new ioctls.
- unistd: setsid()/getsid()/setpgid() stubs consistent with the
  existing getpgrp()/getpgid() single-session model (sid == pgid ==
  pid; setpgid only succeeds for pgid == pid).

Declare the new prototypes in unistd.h (tcgetsid was already in
termios.h) and register all sources in the Make.defs/CMakeLists.

Group-broadcast signalling (kill(-pgrp)) remains unsupported, so
tty signals still target the single dev->pid; a real session/process
group model is left as a follow-up.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: L The size of the change in this PR is large labels Aug 6, 2026
@xiaoxiang781216
xiaoxiang781216 merged commit db9531f into apache:releases/13.0 Aug 6, 2026
17 of 42 checks passed
@jerpelea
jerpelea deleted the bp-19184 branch August 6, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants