Arguments:
<listen-port> Port or file descriptor to listen for TCP connections
- <terminal-cmd>... The command to run connected via a proxied PTY
+ <terminal-cmd>... The command to run connected via a proxied pty
Options:
--authport <authport> Port to relay auth-request, default 85
}
pub fn use_listen_port_as_fd(&self) -> bool {
- match self.listen_port {
- PortOrFd::Fd(_) => true,
- _ => false,
- }
+ matches!(self.listen_port, PortOrFd::Fd(_))
}
}
use crate::cli::{Options, PortOrFd};
mod pty;
-use crate::pty::{make_controlling_terminal, PTY};
+use crate::pty::{make_controlling_terminal, Pty};
const MSG_TYPE_DATA: u8 = 0;
const MSG_TYPE_RESIZE: u8 = 1;
None
}
-fn process_queue(buf: &mut ByteBuffer, pty: &mut PTY) -> Option<usize> {
+fn process_queue(buf: &mut ByteBuffer, pty: &mut Pty) -> Option<usize> {
if buf.is_empty() {
return None;
}
) -> Result<(TcpStream, u16)> {
let listener = match listen_port {
PortOrFd::Fd(fd) => unsafe { std::net::TcpListener::from_raw_fd(*fd) },
- PortOrFd::Port(port) => std::net::TcpListener::bind((hostname, *port as u16))?,
+ PortOrFd::Port(port) => std::net::TcpListener::bind((hostname, *port))?,
};
let port = listener.local_addr()?.port();
let mut listener = TcpListener::from_std(listener);
}
}
-fn run_pty<'a>(mut full_cmd: impl Iterator<Item = &'a OsString>) -> Result<PTY> {
+fn run_pty<'a>(mut full_cmd: impl Iterator<Item = &'a OsString>) -> Result<Pty> {
let cmd_exe = full_cmd.next().unwrap();
let params = full_cmd; // rest
- let (mut pty, secondary_name) = PTY::new().map_err(io_err_other)?;
+ let (mut pty, secondary_name) = Pty::new().map_err(io_err_other)?;
let mut filtered_env: HashMap<OsString, OsString> = std::env::vars_os()
- .filter(|&(ref k, _)| {
+ .filter(|(k, _)| {
k == "PATH"
|| k == "USER"
|| k == "HOME"
//! Helper for creating a pseudo-terminal
//!
-//! see [PTY](struct.PTY.html) for an example on how to use it
+//! see [Pty](struct.Pty.html) for an example on how to use it
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
ioctl_write_int_bad!(set_controlling_tty, libc::TIOCSCTTY);
ioctl_write_ptr_bad!(set_size, libc::TIOCSWINSZ, nix::pty::Winsize);
-/// Represents a PTY
+/// Represents a pty.
///
/// Implements Read and Write (from std::io) so one can simply use it
/// to read and write the terminal of a child process
/// }
///
/// fn main() -> Result<()> {
-/// let (mut pty, secondary) = PTY::new()?;
+/// let (mut pty, secondary) = Pty::new()?;
///
/// let child = fork()?;
/// if child == 0 {
/// Ok(())
/// }
/// ```
-pub struct PTY {
+pub struct Pty {
primary: PtyMaster,
}
Ok(())
}
-impl PTY {
- /// Creates a new PTY by opening /dev/ptmx and returns
- /// a new PTY and the path to the secondary terminal on success.
+impl Pty {
+ /// Creates a new pty by opening /dev/ptmx and returns
+ /// a new pty and the path to the secondary terminal on success.
pub fn new() -> Result<(Self, String)> {
let primary =
posix_openpt(OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK | OFlag::O_CLOEXEC)?;
}
}
-impl std::io::Read for PTY {
+impl std::io::Read for Pty {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
Ok(nix::unistd::read(self.primary.as_raw_fd(), buf)?)
}
}
-impl std::io::Write for PTY {
+impl std::io::Write for Pty {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
Ok(nix::unistd::write(self.primary.as_raw_fd(), buf)?)
}
}
}
-impl AsRawFd for PTY {
+impl AsRawFd for Pty {
fn as_raw_fd(&self) -> RawFd {
self.primary.as_raw_fd()
}
}
-impl AsFd for PTY {
+impl AsFd for Pty {
fn as_fd(&self) -> BorrowedFd<'_> {
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
}