diff --git a/crates/runc-shim/Cargo.toml b/crates/runc-shim/Cargo.toml index ef4e4a78..1ff4dd4b 100644 --- a/crates/runc-shim/Cargo.toml +++ b/crates/runc-shim/Cargo.toml @@ -39,6 +39,10 @@ uuid.workspace = true # Async dependencies async-trait.workspace = true tokio = { workspace = true, features = ["full"] } +rustix = { version = "1", features = ["termios"] } + +[package.metadata.cargo-machete] +ignored = ["libc"] [target.'cfg(target_os = "linux")'.dependencies] cgroups-rs.workspace = true diff --git a/crates/runc-shim/src/processes.rs b/crates/runc-shim/src/processes.rs index 16c1295c..42d4d185 100644 --- a/crates/runc-shim/src/processes.rs +++ b/crates/runc-shim/src/processes.rs @@ -14,23 +14,19 @@ limitations under the License. */ -use std::{ - os::unix::io::AsRawFd, - sync::{Arc, Mutex}, -}; +use std::sync::{Arc, Mutex}; use async_trait::async_trait; use containerd_shim::{ - ioctl_set_winsz, protos::{ api::{ProcessInfo, StateResponse, Status}, cgroups::metrics::Metrics, protobuf::well_known_types::timestamp::Timestamp, }, - util::asyncify, Console, Result, }; use oci_spec::runtime::LinuxResources; +use rustix::termios::{tcsetwinsize, Winsize}; use time::OffsetDateTime; use tokio::{ fs::File, @@ -174,17 +170,14 @@ where async fn resize_pty(&mut self, height: u32, width: u32) -> Result<()> { if let Some(console) = self.console.as_ref() { - let w = libc::winsize { + let w = Winsize { ws_row: height as u16, ws_col: width as u16, ws_xpixel: 0, ws_ypixel: 0, }; - let fd = console.file.as_raw_fd(); - asyncify(move || -> Result<()> { - unsafe { ioctl_set_winsz(fd, &w).map(|_x| ()).map_err(Into::into) } - }) - .await?; + tcsetwinsize(&console.file, w) + .map_err(|e| containerd_shim::Error::Other(e.to_string()))?; } Ok(()) } diff --git a/crates/shim/src/lib.rs b/crates/shim/src/lib.rs index 46236200..fa2d5b43 100644 --- a/crates/shim/src/lib.rs +++ b/crates/shim/src/lib.rs @@ -17,24 +17,17 @@ #![cfg_attr(feature = "docs", doc = include_str!("../README.md"))] use std::{fs::File, path::PathBuf}; +#[cfg(windows)] +use std::{fs::OpenOptions, os::windows::prelude::OpenOptionsExt}; #[cfg(unix)] use std::{os::unix::net::UnixListener, path::Path}; pub use containerd_shim_protos as protos; -#[cfg(unix)] -use nix::ioctl_write_ptr_bad; pub use protos::{ shim::shim::DeleteResponse, ttrpc::{context::Context, Result as TtrpcResult}, }; use sha2::{Digest, Sha256}; - -#[cfg(unix)] -ioctl_write_ptr_bad!(ioctl_set_winsz, libc::TIOCSWINSZ, libc::winsize); - -#[cfg(windows)] -use std::{fs::OpenOptions, os::windows::prelude::OpenOptionsExt}; - #[cfg(windows)] use windows_sys::Win32::Storage::FileSystem::FILE_FLAG_OVERLAPPED;