From 595e8b03682094afdee0177ec3b1ad4c656ea476 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Aug 2023 11:56:52 +0000 Subject: [PATCH 1/2] build(deps): bump nix from 0.26.2 to 0.27.1 Bumps [nix](https://github.com/nix-rust/nix) from 0.26.2 to 0.27.1. - [Changelog](https://github.com/nix-rust/nix/blob/master/CHANGELOG.md) - [Commits](https://github.com/nix-rust/nix/compare/v0.26.2...v0.27.1) --- updated-dependencies: - dependency-name: nix dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 29 ++++++++++++++++------------- conmon-rs/server/Cargo.toml | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4c730e9ab..eb90f1762f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -348,7 +348,7 @@ dependencies = [ "memchr", "mockall", "multimap", - "nix 0.26.2", + "nix 0.27.1", "notify", "once_cell", "opentelemetry", @@ -1066,7 +1066,7 @@ dependencies = [ "hmac", "libc", "log", - "nix 0.26.2", + "nix 0.26.4", "nom", "once_cell", "serde", @@ -1232,16 +1232,25 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.2" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" dependencies = [ "bitflags 1.3.2", "cfg-if", "libc", "memoffset 0.7.1", - "pin-utils", - "static_assertions", +] + +[[package]] +name = "nix" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +dependencies = [ + "bitflags 2.3.3", + "cfg-if", + "libc", ] [[package]] @@ -1512,7 +1521,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "059a34f111a9dee2ce1ac2826a68b24601c4298cfeb1a587c3cb493d5ab46f52" dependencies = [ "libc", - "nix 0.26.2", + "nix 0.22.3", ] [[package]] @@ -1866,12 +1875,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strsim" version = "0.10.0" diff --git a/conmon-rs/server/Cargo.toml b/conmon-rs/server/Cargo.toml index 80f211194c..3d68233256 100644 --- a/conmon-rs/server/Cargo.toml +++ b/conmon-rs/server/Cargo.toml @@ -21,7 +21,7 @@ libc = "0.2.147" libsystemd = "0.6.0" memchr = "2.6.0" multimap = "0.9.0" -nix = "0.26.2" +nix = "0.27.1" notify = "6.1.1" once_cell = "1.18.0" opentelemetry = { version = "0.20.0", features = ["rt-tokio"] } From a456b0a493d2efd16b4c028a5e3666b960090e42 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Tue, 29 Aug 2023 14:36:09 +0200 Subject: [PATCH 2/2] Fix nix usage Signed-off-by: Sascha Grunert --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + conmon-rs/server/Cargo.toml | 2 +- conmon-rs/server/src/attach.rs | 16 +++++++--------- conmon-rs/server/src/terminal.rs | 19 ++++++++++++------- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb90f1762f..b47c322f0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1148,6 +1148,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.17" @@ -1251,6 +1260,7 @@ dependencies = [ "bitflags 2.3.3", "cfg-if", "libc", + "memoffset 0.9.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2cdc297b39..5a7f116aa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "conmon-rs/common", "conmon-rs/client", diff --git a/conmon-rs/server/Cargo.toml b/conmon-rs/server/Cargo.toml index 3d68233256..f435385922 100644 --- a/conmon-rs/server/Cargo.toml +++ b/conmon-rs/server/Cargo.toml @@ -21,7 +21,7 @@ libc = "0.2.147" libsystemd = "0.6.0" memchr = "2.6.0" multimap = "0.9.0" -nix = "0.27.1" +nix = { version = "0.27.1", features = ["fs", "hostname", "mount", "sched", "signal", "socket", "term", "user"] } notify = "6.1.1" once_cell = "1.18.0" opentelemetry = { version = "0.20.0", features = ["rt-tokio"] } diff --git a/conmon-rs/server/src/attach.rs b/conmon-rs/server/src/attach.rs index 441ace5524..1d79cf02d0 100644 --- a/conmon-rs/server/src/attach.rs +++ b/conmon-rs/server/src/attach.rs @@ -9,10 +9,9 @@ use nix::{ }; use std::{ convert::From, - os::unix::{ - fs::PermissionsExt, - io::{FromRawFd, RawFd}, - net, + os::{ + fd::{AsRawFd, OwnedFd}, + unix::fs::PermissionsExt, }, path::{Path, PathBuf}, }; @@ -154,13 +153,13 @@ impl Attach { let (shortened_path, _parent_dir) = Listener::::default().shorten_socket_path(path)?; let addr = UnixAddr::new(&shortened_path).context("create socket addr")?; - bind(fd, &addr).context("bind socket fd")?; + bind(fd.as_raw_fd(), &addr).context("bind socket fd")?; let metadata = path.metadata()?; let mut permissions = metadata.permissions(); permissions.set_mode(0o700); - listen(fd, 10).context("listen on socket fd")?; + listen(&fd, 10).context("listen on socket fd")?; task::spawn( async move { @@ -177,15 +176,14 @@ impl Attach { } async fn start( - fd: RawFd, + fd: OwnedFd, read_half_tx: Sender>, write_half_tx: Sender, token: CancellationToken, stop_after_stdin_eof: bool, ) -> Result<()> { debug!("Start listening on attach socket"); - let listener = UnixListener::from_std(unsafe { net::UnixListener::from_raw_fd(fd) }) - .context("create unix listener")?; + let listener = UnixListener::from_std(fd.into()).context("create unix listener")?; loop { match listener.accept().await { Ok((stream, _)) => { diff --git a/conmon-rs/server/src/terminal.rs b/conmon-rs/server/src/terminal.rs index a1e85a1214..0bdf04aa9e 100644 --- a/conmon-rs/server/src/terminal.rs +++ b/conmon-rs/server/src/terminal.rs @@ -17,7 +17,7 @@ use sendfd::RecvWithFd; use std::{ io::{self, ErrorKind, Read, Write}, os::{ - fd::{AsRawFd, FromRawFd, OwnedFd}, + fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd}, unix::{fs::PermissionsExt, io::RawFd}, }, path::PathBuf, @@ -112,9 +112,9 @@ impl Terminal { self.set_tty(Arc::downgrade(&fd).into()); debug!("Changing terminal settings"); - let mut term = termios::tcgetattr(fd.as_raw_fd())?; + let mut term = termios::tcgetattr(&fd)?; term.output_flags |= OutputFlags::ONLCR; - termios::tcsetattr(fd.as_raw_fd(), SetArg::TCSANOW, &term)?; + termios::tcsetattr(&fd, SetArg::TCSANOW, &term)?; let attach_clone = self.attach.clone(); let logger_clone = self.logger.clone(); @@ -268,7 +268,6 @@ mod tests { use crate::{attach::SharedContainerAttach, container_log::ContainerLog}; use nix::pty; use sendfd::SendWithFd; - use std::os::unix::io::FromRawFd; #[tokio::test(flavor = "multi_thread")] async fn new_success() -> Result<()> { @@ -285,7 +284,7 @@ mod tests { loop { let ready = stream.ready(Interest::WRITABLE).await?; if ready.is_writable() { - match stream.send_with_fd(b"test", &[res.master]) { + match stream.send_with_fd(b"test", &[res.master.as_raw_fd()]) { Ok(_) => break, Err(ref e) if e.kind() == ErrorKind::WouldBlock => continue, Err(e) => anyhow::bail!(e), @@ -297,8 +296,8 @@ mod tests { assert!(!sut.path().exists()); // Write to the slave - let mut file = unsafe { fs::File::from_raw_fd(res.slave) }; - file.write_all(b"test").await?; + let mut file: std::fs::File = res.slave.into(); + file.write_all(b"test")?; Ok(()) } @@ -322,6 +321,12 @@ impl AsRawFd for TerminalFd { } } +impl AsFd for TerminalFd { + fn as_fd(&self) -> BorrowedFd { + self.0.as_fd() + } +} + impl AsyncRead for &TerminalFd { fn poll_read( self: Pin<&mut Self>,