drivers/serial: add job-control TTY ioctls#19184
Merged
Merged
Conversation
xiaoxiang781216
requested review from
Donny9,
GUIDINGLI,
acassis,
btashton,
hartmannathan and
jerpelea
as code owners
June 21, 2026 03:08
xiaoxiang781216
force-pushed
the
upstream-job-control-tty
branch
from
June 21, 2026 03:20
146ac2a to
c776065
Compare
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>
xiaoxiang781216
force-pushed
the
upstream-job-control-tty
branch
from
June 21, 2026 04:08
c776065 to
87222fd
Compare
acassis
approved these changes
Jun 21, 2026
Contributor
|
@xiaoxiang781216 so Ctrl+Z will not "freeZe" a process the same way it does on Linux? For example on Linux: |
Contributor
Author
|
@FelipeMdeO this patch may help you port dropbear. |
linguini1
approved these changes
Jun 23, 2026
FelipeMdeO
added a commit
to FelipeMdeO/nuttx-apps
that referenced
this pull request
Jun 23, 2026
Integrated SSH daemon authenticating against FSUTILS_PASSWD, with an ECDSA P-256 host key and an NSH session over a PTY per connection. Built from the upstream Dropbear tarball (pinned commit) and patched for NuttX, using Dropbear's bundled libtomcrypt for all crypto. setsid() is taken from NuttX libc (apache/nuttx#19184) instead of a local prototype. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
FelipeMdeO
added a commit
to FelipeMdeO/nuttx-apps
that referenced
this pull request
Jun 24, 2026
Integrated SSH daemon authenticating against FSUTILS_PASSWD, with an ECDSA P-256 host key and an NSH session over a PTY per connection. Built from the upstream Dropbear tarball (pinned commit) and patched for NuttX, using Dropbear's bundled libtomcrypt for all crypto. setsid() (apache/nuttx#19184) and link() now come from NuttX, not local stubs. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
FelipeMdeO
added a commit
to FelipeMdeO/nuttx-apps
that referenced
this pull request
Jun 24, 2026
Integrated SSH daemon authenticating against FSUTILS_PASSWD, with an ECDSA P-256 host key and an NSH session over a PTY per connection. Built from the upstream Dropbear tarball (pinned commit) and patched for NuttX, using Dropbear's bundled libtomcrypt for all crypto. setsid() (apache/nuttx#19184) and link() now come from NuttX, not local stubs. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
FelipeMdeO
added a commit
to FelipeMdeO/nuttx-apps
that referenced
this pull request
Jun 25, 2026
Integrated SSH daemon authenticating against FSUTILS_PASSWD, with an ECDSA P-256 host key and an NSH session over a PTY per connection. Built from the upstream Dropbear tarball (pinned commit) and patched for NuttX, using Dropbear's bundled libtomcrypt for all crypto. setsid() (apache/nuttx#19184) and link() now come from NuttX, not local stubs. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
acassis
pushed a commit
to apache/nuttx-apps
that referenced
this pull request
Jun 27, 2026
Integrated SSH daemon authenticating against FSUTILS_PASSWD, with an ECDSA P-256 host key and an NSH session over a PTY per connection. Built from the upstream Dropbear tarball (pinned commit) and patched for NuttX, using Dropbear's bundled libtomcrypt for all crypto. setsid() (apache/nuttx#19184) and link() now come from NuttX, not local stubs. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add lightweight job-control/controlling-terminal support for serial and PTY drivers on systems without a real POSIX session/process-group model.
NuttX currently treats each task as its own process group. This patch keeps that model (
pgrp == pid) and adds the missing APIs/ioctls needed by portable software such as dropbear/socat:TIOCGPGRP,TIOCSPGRP, andTIOCGSIDioctl numbers.serial.candpty.cto support:TIOCSCTTY:arg > 0preserves the existing NuttX convention of passing an explicit target PID (used by NSH for foreground commands), whilearg == 0follows POSIX-style flag semantics and selects the calling task.TIOCGPGRP/TIOCGSID: return the current foreground PID.TIOCSPGRP: set the foreground PID (or caller when pgrp is zero).tcgetpgrp(),tcsetpgrp(),tcgetsid()over the new ioctls.setsid(),getsid(),setpgid()stubs consistent with the existing single-member process-group model.Documentation/components/drivers/character/serial.rst.Rationale
This avoids regressing existing NSH behavior where
TIOCSCTTYis used to register a spawned foreground command as the Ctrl-C/Ctrl-Z signal target, while also supporting the POSIX-styleioctl(fd, TIOCSCTTY, 0)pattern used by dropbear and similar software.Group-broadcast signaling (
kill(-pgrp, signo)) remains unsupported, so TTY-generated signals still target a single foreground PID.Testing
sim:nsh boot and ctrl+c work as before.