Skip to content

Commit

Permalink
Merge pull request #1651 from containers/dependabot/cargo/nix-0.27.1
Browse files Browse the repository at this point in the history
build(deps): bump nix from 0.26.2 to 0.27.1
  • Loading branch information
openshift-merge-robot authored Sep 18, 2023
2 parents 10776ca + a456b0a commit 2a9cee4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 30 deletions.
39 changes: 26 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion conmon-rs/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ libc = "0.2.148"
libsystemd = "0.6.0"
memchr = "2.6.3"
multimap = "0.9.0"
nix = "0.26.2"
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"] }
Expand Down
16 changes: 7 additions & 9 deletions conmon-rs/server/src/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -154,13 +153,13 @@ impl Attach {
let (shortened_path, _parent_dir) =
Listener::<DefaultListener>::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 {
Expand All @@ -177,15 +176,14 @@ impl Attach {
}

async fn start(
fd: RawFd,
fd: OwnedFd,
read_half_tx: Sender<Vec<u8>>,
write_half_tx: Sender<Message>,
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, _)) => {
Expand Down
19 changes: 12 additions & 7 deletions conmon-rs/server/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<()> {
Expand All @@ -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),
Expand All @@ -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(())
}
Expand All @@ -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>,
Expand Down

0 comments on commit 2a9cee4

Please sign in to comment.