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