Skip to content

Commit 27898a5

Browse files
committed
fix(pty) : Use more safe package rustix to resize pty
avoid using the nix's unsafe ioctl call Signed-off-by: jokemanfire <[email protected]>
1 parent c1bd8a7 commit 27898a5

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

crates/runc-shim/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ uuid.workspace = true
3939
# Async dependencies
4040
async-trait.workspace = true
4141
tokio = { workspace = true, features = ["full"] }
42+
rustix = { version = "1", features = ["termios"] }
4243

4344
[target.'cfg(target_os = "linux")'.dependencies]
4445
cgroups-rs.workspace = true

crates/runc-shim/src/processes.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,19 @@
1414
limitations under the License.
1515
*/
1616

17-
use std::{
18-
os::unix::io::AsRawFd,
19-
sync::{Arc, Mutex},
20-
};
17+
use std::sync::{Arc, Mutex};
2118

2219
use async_trait::async_trait;
2320
use containerd_shim::{
24-
ioctl_set_winsz,
2521
protos::{
2622
api::{ProcessInfo, StateResponse, Status},
2723
cgroups::metrics::Metrics,
2824
protobuf::well_known_types::timestamp::Timestamp,
2925
},
30-
util::asyncify,
3126
Console, Result,
3227
};
3328
use oci_spec::runtime::LinuxResources;
29+
use rustix::termios::{tcsetwinsize, Winsize};
3430
use time::OffsetDateTime;
3531
use tokio::{
3632
fs::File,
@@ -174,17 +170,14 @@ where
174170

175171
async fn resize_pty(&mut self, height: u32, width: u32) -> Result<()> {
176172
if let Some(console) = self.console.as_ref() {
177-
let w = libc::winsize {
173+
let w = Winsize {
178174
ws_row: height as u16,
179175
ws_col: width as u16,
180176
ws_xpixel: 0,
181177
ws_ypixel: 0,
182178
};
183-
let fd = console.file.as_raw_fd();
184-
asyncify(move || -> Result<()> {
185-
unsafe { ioctl_set_winsz(fd, &w).map(|_x| ()).map_err(Into::into) }
186-
})
187-
.await?;
179+
tcsetwinsize(&console.file, w)
180+
.map_err(|e| containerd_shim::Error::Other(e.to_string()))?;
188181
}
189182
Ok(())
190183
}

crates/shim/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,17 @@
1717
#![cfg_attr(feature = "docs", doc = include_str!("../README.md"))]
1818

1919
use std::{fs::File, path::PathBuf};
20+
#[cfg(windows)]
21+
use std::{fs::OpenOptions, os::windows::prelude::OpenOptionsExt};
2022
#[cfg(unix)]
2123
use std::{os::unix::net::UnixListener, path::Path};
2224

2325
pub use containerd_shim_protos as protos;
24-
#[cfg(unix)]
25-
use nix::ioctl_write_ptr_bad;
2626
pub use protos::{
2727
shim::shim::DeleteResponse,
2828
ttrpc::{context::Context, Result as TtrpcResult},
2929
};
3030
use sha2::{Digest, Sha256};
31-
32-
#[cfg(unix)]
33-
ioctl_write_ptr_bad!(ioctl_set_winsz, libc::TIOCSWINSZ, libc::winsize);
34-
35-
#[cfg(windows)]
36-
use std::{fs::OpenOptions, os::windows::prelude::OpenOptionsExt};
37-
3831
#[cfg(windows)]
3932
use windows_sys::Win32::Storage::FileSystem::FILE_FLAG_OVERLAPPED;
4033

0 commit comments

Comments
 (0)