Skip to content

Commit

Permalink
feat: update to nix 0.27.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vthib authored and JohnTitor committed Nov 22, 2023
1 parent 5e5c688 commit 0458e60
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ netlink-packet-utils = { version = "0.5" }
netlink-packet-route = { version = "0.17" }
netlink-packet-core = { version = "0.7" }
netlink-proto = { default-features = false, version = "0.11" }
nix = { version = "0.26.1", default-features = false, features = ["fs", "mount", "sched", "signal"] }
nix = { version = "0.27.1", default-features = false, features = ["fs", "mount", "sched", "signal"] }
tokio = { version = "1.0.1", features = ["rt"], optional = true}
async-global-executor = { version = "2.0.2", optional = true }

Expand Down
7 changes: 5 additions & 2 deletions src/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use nix::{
},
unistd::{fork, ForkResult},
};
use std::{option::Option, path::Path, process::exit};
use std::{option::Option, os::fd::BorrowedFd, path::Path, process::exit};

// if "only" smol or smol+tokio were enabled, we use smol because
// it doesn't require an active tokio runtime - just to be sure.
Expand Down Expand Up @@ -329,7 +329,10 @@ impl NetworkNamespace {
}

setns_flags.insert(CloneFlags::CLONE_NEWNET);
if let Err(e) = nix::sched::setns(fd, setns_flags) {
if let Err(e) = nix::sched::setns(
unsafe { BorrowedFd::borrow_raw(fd) },
setns_flags,
) {
log::error!("setns error: {}", e);
let err_msg = format!("setns error: {e}");
let _ = nix::unistd::unlink(ns_path);
Expand Down
6 changes: 3 additions & 3 deletions src/traffic_control/add_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl TrafficFilterNewRequest {

#[cfg(test)]
mod test {
use std::{fs::File, os::unix::io::AsRawFd, path::Path};
use std::{fs::File, os::fd::AsFd, path::Path};

use futures::stream::TryStreamExt;
use netlink_packet_route::LinkMessage;
Expand Down Expand Up @@ -193,7 +193,7 @@ mod test {
// entry new ns
let ns_path = Path::new(NETNS_PATH);
let file = File::open(ns_path.join(path)).unwrap();
setns(file.as_raw_fd(), CloneFlags::CLONE_NEWNET).unwrap();
setns(file.as_fd(), CloneFlags::CLONE_NEWNET).unwrap();

Self {
path: path.to_string(),
Expand All @@ -205,7 +205,7 @@ mod test {
impl Drop for Netns {
fn drop(&mut self) {
println!("exit ns: {}", self.path);
setns(self.last.as_raw_fd(), CloneFlags::CLONE_NEWNET).unwrap();
setns(self.last.as_fd(), CloneFlags::CLONE_NEWNET).unwrap();

let ns_path = Path::new(NETNS_PATH).join(&self.path);
nix::mount::umount2(&ns_path, nix::mount::MntFlags::MNT_DETACH)
Expand Down
6 changes: 3 additions & 3 deletions src/traffic_control/add_qdisc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl QDiscNewRequest {

#[cfg(test)]
mod test {
use std::{fs::File, os::unix::io::AsRawFd, path::Path};
use std::{fs::File, os::fd::AsFd, path::Path};

use futures::stream::TryStreamExt;
use nix::sched::{setns, CloneFlags};
Expand Down Expand Up @@ -106,7 +106,7 @@ mod test {
// entry new ns
let ns_path = Path::new(NETNS_PATH);
let file = File::open(ns_path.join(path)).unwrap();
setns(file.as_raw_fd(), CloneFlags::CLONE_NEWNET).unwrap();
setns(file.as_fd(), CloneFlags::CLONE_NEWNET).unwrap();

Self {
path: path.to_string(),
Expand All @@ -118,7 +118,7 @@ mod test {
impl Drop for Netns {
fn drop(&mut self) {
println!("exit ns: {}", self.path);
setns(self.last.as_raw_fd(), CloneFlags::CLONE_NEWNET).unwrap();
setns(self.last.as_fd(), CloneFlags::CLONE_NEWNET).unwrap();

let ns_path = Path::new(NETNS_PATH).join(&self.path);
nix::mount::umount2(&ns_path, nix::mount::MntFlags::MNT_DETACH)
Expand Down

0 comments on commit 0458e60

Please sign in to comment.