From 1744adb7c14b9a68acd2a102342368738a67939f Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Tue, 12 Aug 2025 02:38:23 -0400 Subject: [PATCH] Add _POSIX_VDISABLE to disable control chars This is a POSIX extension to disable control chars when set in the c_cc array. Fish and other programs use it. See: * redox-os/relibc!689 * redox-os/termios!3 --- ptyd/src/pty.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/ptyd/src/pty.rs b/ptyd/src/pty.rs index 58513ca37a..36ebcdc84f 100644 --- a/ptyd/src/pty.rs +++ b/ptyd/src/pty.rs @@ -52,6 +52,9 @@ impl Pty { let cc = self.termios.c_cc; let is_cc = |b: u8, i: usize| -> bool { b != 0 && b == cc[i] }; + // TODO: Delete this constant once termios is bumped (it's in termios). + const _POSIX_VDISABLE: u8 = 0; + let is_vdisable = |i: usize| -> bool { cc[i] == _POSIX_VDISABLE }; let inlcr = ifl & INLCR == INLCR; let igncr = ifl & IGNCR == IGNCR; @@ -68,7 +71,7 @@ impl Pty { for &byte in buf.iter() { let mut b = byte; - // Input tranlation + // Input translation if b == b'\n' { if inlcr { b = b'\r'; @@ -126,7 +129,7 @@ impl Pty { b = 0; } - if is_cc(b, VERASE) { + if is_cc(b, VERASE) && !is_vdisable(VERASE) { if let Some(_c) = self.cooked.pop() { if echoe { self.output(&[8, b' ', 8]); @@ -153,25 +156,34 @@ impl Pty { } if isig { - if is_cc(b, VINTR) { + if is_cc(b, VINTR) && !is_vdisable(VINTR) { if self.pgrp != 0 { - let _ = libredox::call::kill(-(self.pgrp as isize) as usize, libredox::flag::SIGINT as _); + let _ = libredox::call::kill( + -(self.pgrp as isize) as usize, + libredox::flag::SIGINT as _, + ); } b = 0; } - if is_cc(b, VQUIT) { + if is_cc(b, VQUIT) && !is_vdisable(VQUIT) { if self.pgrp != 0 { - let _ = libredox::call::kill(-(self.pgrp as isize) as usize, libredox::flag::SIGQUIT as _); + let _ = libredox::call::kill( + -(self.pgrp as isize) as usize, + libredox::flag::SIGQUIT as _, + ); } b = 0; } - if is_cc(b, VSUSP) { + if is_cc(b, VSUSP) && !is_vdisable(VSUSP) { if self.pgrp != 0 { - let _ = libredox::call::kill(-(self.pgrp as isize) as usize, libredox::flag::SIGTSTP as _); + let _ = libredox::call::kill( + -(self.pgrp as isize) as usize, + libredox::flag::SIGTSTP as _, + ); } b = 0;