Skip to content

Commit

Permalink
Merge pull request #863 from utam0k/nix-0.24.0
Browse files Browse the repository at this point in the history
Follow the breaking changes of nix
  • Loading branch information
Furisto authored Apr 23, 2022
2 parents 712ddbb + f2a645f commit f5a0076
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 96 deletions.
71 changes: 35 additions & 36 deletions crates/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 crates/libcgroups/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ systemd = ["v2", "dbus"]
cgroupsv2_devices = ["rbpf", "libbpf-sys", "errno", "libc"]

[dependencies]
nix = "0.23.1"
nix = "0.24.0"
procfs = "0.12.0"
log = "0.4"
anyhow = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/libcontainer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ futures = { version = "0.3", features = ["thread-pool"] }
libc = "0.2.124"
log = "0.4"
mio = { version = "0.8.2", features = ["os-ext", "os-poll"] }
nix = "0.23.1"
nix = "0.24.0"
oci-spec = { git = "https://github.com/containers/oci-spec-rs", rev = "89376af" }
path-clean = "0.1.0"
procfs = "0.12.0"
Expand Down
29 changes: 15 additions & 14 deletions crates/libcontainer/src/process/channel.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::process::message::Message;
use anyhow::{bail, Context, Result};
use nix::{
sys::{socket, uio},
sys::socket::{self, UnixAddr},
unistd::{self, Pid},
};
use serde::{Deserialize, Serialize};
use std::{
io::{IoSlice, IoSliceMut},
marker::PhantomData,
os::unix::prelude::{AsRawFd, RawFd},
};
Expand Down Expand Up @@ -255,27 +256,27 @@ impl<T> Sender<T>
where
T: Serialize,
{
fn send_iovec(&mut self, iov: &[uio::IoVec<&[u8]>], fds: Option<&[RawFd]>) -> Result<usize> {
fn send_iovec(&mut self, iov: &[IoSlice], fds: Option<&[RawFd]>) -> Result<usize> {
let cmsgs = if let Some(fds) = fds {
vec![socket::ControlMessage::ScmRights(fds)]
} else {
vec![]
};
socket::sendmsg(self.sender, iov, &cmsgs, socket::MsgFlags::empty(), None)
socket::sendmsg::<UnixAddr>(self.sender, iov, &cmsgs, socket::MsgFlags::empty(), None)
.map_err(|e| e.into())
}

fn send_slice_with_len(&mut self, data: &[u8], fds: Option<&[RawFd]>) -> Result<usize> {
let len = data.len() as u64;
// Here we prefix the length of the data onto the serialized data.
let iov = [
uio::IoVec::from_slice(unsafe {
IoSlice::new(unsafe {
std::slice::from_raw_parts(
(&len as *const u64) as *const u8,
std::mem::size_of::<u64>(),
)
}),
uio::IoVec::from_slice(data),
IoSlice::new(data),
];
self.send_iovec(&iov[..], fds)
}
Expand Down Expand Up @@ -305,25 +306,26 @@ where
{
fn peek_size_iovec(&mut self) -> Result<u64> {
let mut len: u64 = 0;
let iov = [uio::IoVec::from_mut_slice(unsafe {
let mut iov = [IoSliceMut::new(unsafe {
std::slice::from_raw_parts_mut(
(&mut len as *mut u64) as *mut u8,
std::mem::size_of::<u64>(),
)
})];
let _ = socket::recvmsg(self.receiver, &iov, None, socket::MsgFlags::MSG_PEEK)?;
let _ =
socket::recvmsg::<UnixAddr>(self.receiver, &mut iov, None, socket::MsgFlags::MSG_PEEK)?;
match len {
0 => bail!("channel connection broken"),
_ => Ok(len),
}
}

fn recv_into_iovec<F>(&mut self, iov: &[uio::IoVec<&mut [u8]>]) -> Result<(usize, Option<F>)>
fn recv_into_iovec<F>(&mut self, iov: &mut [IoSliceMut]) -> Result<(usize, Option<F>)>
where
F: Default + AsMut<[RawFd]>,
{
let mut cmsgspace = nix::cmsg_space!(F);
let msg = socket::recvmsg(
let msg = socket::recvmsg::<UnixAddr>(
self.receiver,
iov,
Some(&mut cmsgspace),
Expand All @@ -347,7 +349,6 @@ where
.map(|fds| {
let mut fds_array: F = Default::default();
<F as AsMut<[RawFd]>>::as_mut(&mut fds_array).clone_from_slice(&fds);

fds_array
});

Expand All @@ -362,16 +363,16 @@ where
let mut len: u64 = 0;
let mut buf = vec![0u8; msg_len as usize];
let (bytes, fds) = {
let iov = [
uio::IoVec::from_mut_slice(unsafe {
let mut iov = [
IoSliceMut::new(unsafe {
std::slice::from_raw_parts_mut(
(&mut len as *mut u64) as *mut u8,
std::mem::size_of::<u64>(),
)
}),
uio::IoVec::from_mut_slice(&mut buf),
IoSliceMut::new(&mut buf),
];
self.recv_into_iovec(&iov)?
self.recv_into_iovec(&mut iov)?
};

match bytes {
Expand Down
11 changes: 5 additions & 6 deletions crates/libcontainer/src/process/container_main_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::{
};
use anyhow::{Context, Result};
use nix::{
sys::{socket, uio},
sys::socket::{self, UnixAddr},
unistd::{self, Pid},
};
use oci_spec::runtime;
use std::path::Path;
use std::{io::IoSlice, path::Path};

pub fn container_main_process(container_args: &ContainerArgs) -> Result<Pid> {
// We use a set of channels to communicate between parent and child process.
Expand Down Expand Up @@ -130,8 +130,7 @@ fn sync_seccomp_send_msg(listener_path: &Path, msg: &[u8], fd: i32) -> Result<()
None,
)
.context("failed to create unix domain socket for seccomp listener")?;
let unix_addr =
socket::SockAddr::new_unix(listener_path).context("failed to create unix addr")?;
let unix_addr = socket::UnixAddr::new(listener_path).context("failed to create unix addr")?;
socket::connect(socket, &unix_addr).with_context(|| {
format!(
"failed to connect to seccomp notify listerner path: {:?}",
Expand All @@ -142,10 +141,10 @@ fn sync_seccomp_send_msg(listener_path: &Path, msg: &[u8], fd: i32) -> Result<()
// SCM_RIGHTS message.
// Ref: https://man7.org/linux/man-pages/man3/sendmsg.3p.html
// Ref: https://man7.org/linux/man-pages/man3/cmsg.3.html
let iov = [uio::IoVec::from_slice(msg)];
let iov = [IoSlice::new(msg)];
let fds = [fd];
let cmsgs = socket::ControlMessage::ScmRights(&fds);
socket::sendmsg(socket, &iov, &[cmsgs], socket::MsgFlags::empty(), None)
socket::sendmsg::<UnixAddr>(socket, &iov, &[cmsgs], socket::MsgFlags::empty(), None)
.context("failed to write container state to seccomp listener")?;
// The spec requires the listener socket to be closed immediately after sending.
let _ = unistd::close(socket);
Expand Down
Loading

0 comments on commit f5a0076

Please sign in to comment.