fix(pty) : Use more safe package rustix to resize pty
avoid using the nix's unsafe ioctl call Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
This commit is contained in:
		
							parent
							
								
									c1bd8a78d1
								
							
						
					
					
						commit
						41d7e2febf
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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(()) | ||||
|     } | ||||
|  |  | |||
|  | @ -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; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue