Skip to content

system/cu: drop remote CR, keep local ONLCR - #4290

Open
shenjunyuan-2 wants to merge 2 commits into
apache:masterfrom
shenjunyuan-2:cu-local-crlf
Open

shenjunyuan-2 wants to merge 2 commits into
apache:masterfrom
shenjunyuan-2:cu-local-crlf

Conversation

@shenjunyuan-2

@shenjunyuan-2 shenjunyuan-2 commented Dec 4, 2026 •

Copy link
Copy Markdown

Summary

  • Why: cu puts the local console into raw mode (c_oflag = 0), which
    also clears OPOST/ONLCR on a console that may be shared with a
    background writer such as a syslog daemon on the same UART. That
    writer's bare-LF lines then lose their CR and stagger for the whole cu
    session.
  • How:
    • Commit 1 fixes the existing nxstyle errors in cu_main.c (missing
      blank line after a declaration, case label indentation), which
      checkpatch otherwise reports for any change to the file. No
      functional change.
    • Commit 2 keeps the local console's output processing (OPOST/ONLCR)
      and sets IGNCR on the device line. A remote that is itself a
      console already sends CR-LF; its CR is dropped and the local ONLCR
      adds a single CR back, instead of producing CR CR LF.

Impact

  • New feature or changed behavior: YES. While cu runs, the local
    console keeps its NL -> CR-LF conversion, and CR characters received
    from the device are discarded.
  • User adaptation needed: a remote that relies on a bare CR (progress
    indicators, line redraw) is now shown without it.
  • Build: NO.
  • Hardware: NO.
  • Documentation: NO.
  • Security: NO.
  • Compatibility: see "changed behavior" above.

Testing

I confirm that changes are verified on local setup and works as intended:

  • Build Host: Ubuntu 22.04 x86_64, gcc 13.1.0
  • Target: sim:nsh + CONFIG_SYSTEM_CUTERM=y CONFIG_SERIAL_TERMIOS=y
    CONFIG_SIM_UART_NUMBER=1 CONFIG_SIM_UART_PTY=y

cu -l /dev/ttySIM0 in nsh; the host writes
REM1\r\nP10%\rP99%\r\nREM2\n to the host side of the sim UART PTY.
Bytes that reached the NuttX console:

Testing logs before change (master):

REM1\r\nP10%\rP99%\r\nREM2\n

Testing logs after change:

REM1\r\nP10%P99%\r\nREM2\r\n

The remote CR-LF ends up as a single CR-LF, the bare LF gets its CR from
the console, and the bare CR is dropped.

Also: tools/checkpatch.sh -m clean, sim:nsh + CONFIG_SYSTEM_CUTERM
make and CMake builds pass, ostest exits with status 0. Verified on sim
only.

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is still work in progress (not ready for review).
  • My PR is ready for review and can be safely merged into a codebase.

Comment thread system/cu/cu_main.c Resolved
shenjunyuan added 2 commits December 4, 2026 13:18
Add the missing blank line after the declaration in cu_exit() and indent
the case labels of the switch in cu_cmd() as the coding standard asks.

Signed-off-by: shenjunyuan <shenjunyuan@xiaomi.com>
cu forced its local console to raw (c_oflag = 0), which also cleared
OPOST/ONLCR on a console that may be shared with a background syslog
writer (e.g. the dfx log daemon on the same physical UART).  Concurrent
bare-LF log lines then lost their CR and staggered inside a cu session.

Keep the local console's output post-processing (OPOST/ONLCR) enabled so
the shared console keeps translating NL->CR-LF for every writer.  The
remote may itself be a console that already does NL->CR-LF (e.g. an rpmsg
virtual console on another core); set IGNCR on the remote line so the
incoming CR is discarded and the forwarded stream carries bare LF.  The
local ONLCR then re-inserts a single CR instead of doubling it (\r\r\n).

Signed-off-by: shenjunyuan <shenjunyuan@xiaomi.com>
@shenjunyuan-2 shenjunyuan-2 changed the title system/cu: add -r to drop remote CR and keep local ONLCR system/cu: drop remote CR, keep local ONLCR Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants