diff --git a/crates/libcgroups/src/common.rs b/crates/libcgroups/src/common.rs index 8da8c575c..f3f2e0596 100644 --- a/crates/libcgroups/src/common.rs +++ b/crates/libcgroups/src/common.rs @@ -455,7 +455,7 @@ pub fn get_all_pids(path: &Path) -> Result, WrappedIoError> { let file_path = p.join(CGROUP_PROCS); if file_path.exists() { let file = File::open(&file_path).wrap_open(&file_path)?; - for line in BufReader::new(file).lines().flatten() { + for line in BufReader::new(file).lines().map_while(Result::ok) { result.push(Pid::from_raw( line.parse::() .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err)) diff --git a/crates/libcgroups/src/lib.rs b/crates/libcgroups/src/lib.rs index 12234ef3a..3e57977e4 100644 --- a/crates/libcgroups/src/lib.rs +++ b/crates/libcgroups/src/lib.rs @@ -6,6 +6,7 @@ extern crate quickcheck; #[cfg(test)] +#[allow(unused_imports)] #[macro_use] extern crate mockall; diff --git a/crates/libcgroups/src/systemd/dbus_native/dbus.rs b/crates/libcgroups/src/systemd/dbus_native/dbus.rs index 2aed47baf..fba1d9916 100644 --- a/crates/libcgroups/src/systemd/dbus_native/dbus.rs +++ b/crates/libcgroups/src/systemd/dbus_native/dbus.rs @@ -227,7 +227,7 @@ impl DbusConnection { .filter(|m| m.preamble.mtype == MessageType::MethodReturn) .collect(); - let res = res.get(0).ok_or(DbusError::MethodCallErr( + let res = res.first().ok_or(DbusError::MethodCallErr( "expected method call to have reply, found no reply message".into(), ))?; let mut ctr = 0; diff --git a/crates/libcgroups/src/systemd/dbus_native/proxy.rs b/crates/libcgroups/src/systemd/dbus_native/proxy.rs index 495896175..c69c0db0e 100644 --- a/crates/libcgroups/src/systemd/dbus_native/proxy.rs +++ b/crates/libcgroups/src/systemd/dbus_native/proxy.rs @@ -114,7 +114,7 @@ impl<'conn> Proxy<'conn> { // we are only going to consider first reply, cause... so. // realistically there should only be at most one method return type of message // for a method call - let reply = reply.get(0).ok_or(DbusError::MethodCallErr( + let reply = reply.first().ok_or(DbusError::MethodCallErr( "expected to get a reply for method call, didn't get any".into(), ))?; diff --git a/crates/libcontainer/src/process/intel_rdt.rs b/crates/libcontainer/src/process/intel_rdt.rs index f7527ff71..a61ca14be 100644 --- a/crates/libcontainer/src/process/intel_rdt.rs +++ b/crates/libcontainer/src/process/intel_rdt.rs @@ -348,6 +348,7 @@ fn write_resctrl_schemata( // filesystem is pre-populated. let mut file = OpenOptions::new() .create(true) + .truncate(true) .write(true) .open(schemata) .map_err(IntelRdtError::OpenSchemata)?; diff --git a/crates/libcontainer/src/process/seccomp_listener.rs b/crates/libcontainer/src/process/seccomp_listener.rs index a4cf7f46e..f890163e1 100644 --- a/crates/libcontainer/src/process/seccomp_listener.rs +++ b/crates/libcontainer/src/process/seccomp_listener.rs @@ -128,11 +128,13 @@ mod tests { let scmp_file = std::fs::OpenOptions::new() .write(true) .create(true) + .truncate(true) .open(tmp_dir.path().join("scmp_file"))?; std::fs::OpenOptions::new() .write(true) .create(true) + .truncate(true) .open(tmp_dir.path().join("socket_file.sock"))?; let (mut main_sender, mut main_receiver) = channel::main_channel()?; diff --git a/crates/libcontainer/src/rootfs/mount.rs b/crates/libcontainer/src/rootfs/mount.rs index fc3336553..c0365657c 100644 --- a/crates/libcontainer/src/rootfs/mount.rs +++ b/crates/libcontainer/src/rootfs/mount.rs @@ -78,10 +78,11 @@ impl Mount { match mount.typ().as_deref() { Some("cgroup") => { - match libcgroups::common::get_cgroup_setup().map_err(|err| { + let cgroup_setup = libcgroups::common::get_cgroup_setup().map_err(|err| { tracing::error!("failed to determine cgroup setup: {}", err); MountError::Other(err.into()) - })? { + })?; + match cgroup_setup { Legacy | Hybrid => { #[cfg(not(feature = "v1"))] panic!("libcontainer can't run in a Legacy or Hybrid cgroup setup without the v1 feature"); @@ -521,6 +522,7 @@ impl Mount { if src.is_file() && !dest.exists() { OpenOptions::new() .create(true) + .truncate(true) .write(true) .open(dest) .map_err(|err| { @@ -686,6 +688,7 @@ mod tests { let mount_option_config = parse_mount(mount)?; OpenOptions::new() .create(true) + .truncate(true) .write(true) .open(tmp_dir.path().join("null"))?; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4fc47f6e0..0433f520a 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] profile="default" -channel="1.74.1" +channel="1.77.1" diff --git a/tests/contest/contest/src/tests/cgroups/network.rs b/tests/contest/contest/src/tests/cgroups/network.rs index 27d573bf6..d8a009c1d 100644 --- a/tests/contest/contest/src/tests/cgroups/network.rs +++ b/tests/contest/contest/src/tests/cgroups/network.rs @@ -64,7 +64,7 @@ fn create_spec( // Gets the loopback interface and the first ethernet/wlan interface if it exists fn get_network_interfaces() -> Option<(String, String)> { let interfaces = interfaces(); - let lo_if_name = interfaces.get(0).map(|iface| &iface.name)?; + let lo_if_name = interfaces.first().map(|iface| &iface.name)?; let eth_if_name = interfaces.get(1).map(|iface| &iface.name)?; Some((lo_if_name.to_string(), eth_if_name.to_string())) diff --git a/tests/contest/contest/src/utils/mod.rs b/tests/contest/contest/src/utils/mod.rs index fe546b87a..9f7c3eccb 100644 --- a/tests/contest/contest/src/utils/mod.rs +++ b/tests/contest/contest/src/utils/mod.rs @@ -1,10 +1,11 @@ pub mod support; pub mod test_utils; + pub use support::{ - generate_uuid, get_project_path, get_runtime_path, get_runtimetest_path, is_runtime_runc, - prepare_bundle, set_config, set_runtime_path, + generate_uuid, get_runtime_path, get_runtimetest_path, is_runtime_runc, prepare_bundle, + set_config, }; pub use test_utils::{ create_container, delete_container, get_state, kill_container, test_inside_container, - test_outside_container, ContainerData, State, + test_outside_container, State, }; diff --git a/tests/contest/runtimetest/src/utils.rs b/tests/contest/runtimetest/src/utils.rs index ab991a079..22739265f 100644 --- a/tests/contest/runtimetest/src/utils.rs +++ b/tests/contest/runtimetest/src/utils.rs @@ -55,6 +55,7 @@ fn test_file_write_access(path: &str) -> Result<(), std::io::Error> { fn test_dir_write_access(path: &str) -> Result<(), std::io::Error> { let _ = std::fs::OpenOptions::new() .create(true) + .truncate(true) .write(true) .open(PathBuf::from(path).join("test.txt"))?; Ok(()) @@ -144,6 +145,7 @@ pub fn test_device_access(path: &str) -> Result<(), std::io::Error> { println!("test_device_access path: {path:?}"); let _ = std::fs::OpenOptions::new() .create(true) + .truncate(true) .write(true) .open(PathBuf::from(path).join("null"))?; Ok(()) @@ -153,6 +155,7 @@ pub fn test_device_unaccess(path: &str) -> Result<(), std::io::Error> { println!("test_device_unaccess path: {path:?}"); let _ = std::fs::OpenOptions::new() .create(true) + .truncate(true) .write(true) .open(PathBuf::from(path).join("null"))?; Ok(())