nuttx-apps/netutils/telnetd
Ricard Rosson ac73e41fc3 netutils/telnetd: keep the listen socket out of the standard-stream range
When telnetd_daemon() starts without open standard streams - exactly
what happens when nsh_telnetstart() spawns "telnetd &" before the
console device exists (e.g. CONFIG_NSH_USBCONSOLE boards, where
nsh_initialize() runs before the USB console is connected) - socket()
returns a descriptor in the 0..2 range.  The accept loop's own "go
silent" close(0)..close(2) then destroys the listen socket on the
first iteration: every subsequent accept4() fails with EBADF and the
daemon serves nothing.

Observed on hardware (RP2350, CDC-ACM console + CDC-NCM composite):
the daemon task was alive but port 23 refused every connection; the
thread list showed it looping on the failed accept.  Duplicate the
descriptor above the standard-stream range before using it.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Ricard Rosson <ricard@groundbits.com>
2026-07-23 19:00:43 +01:00
..
CMakeLists.txt netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
Kconfig netutils: Support telnetd in the kernel mode 2022-11-07 15:24:08 +09:00
Make.defs netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
Makefile netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
telnetd_daemon.c netutils/telnetd: keep the listen socket out of the standard-stream range 2026-07-23 19:00:43 +01:00