Files
Matteo Collina 726d4d4b00 src: restore tty state on exit only if changed
ResetStdio() unconditionally writes the terminal attributes recorded at
startup back to stdin and stderr when the process exits, even when the
process never touched the terminal. This clobbers changes made in the
meantime by another process sharing the terminal: in `node -h | less`,
less switches the terminal to raw mode once it receives the first byte
of output, and node switches it back to cooked mode when it exits.

Only restore the recorded attributes when node itself changed the
terminal mode through setRawMode(), or when exiting because of a signal.
Restoring the O_NONBLOCK flag and libuv's own terminal mode reset are
unchanged.

Fixes: https://github.com/nodejs/node/issues/66440
Refs: https://github.com/nodejs/node/issues/35536
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66753
Refs: https://github.com/nodejs/node/pull/66540
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2026-11-13 20:16:19 +00:00
..