mirror of
https://github.com/containers/youki
synced 2024-06-10 00:36:16 +02:00
fix the warnings found by cargo clippy.
This commit is contained in:
parent
7cb78a484d
commit
5088b3632e
|
@ -183,14 +183,12 @@ pub fn create_cgroup_manager<P: Into<PathBuf>>(
|
|||
pub fn get_all_pids(path: &Path) -> Result<Vec<Pid>> {
|
||||
log::debug!("scan pids in folder: {:?}", path);
|
||||
let mut result = vec![];
|
||||
walk_dir(&path, &mut |p| {
|
||||
walk_dir(path, &mut |p| {
|
||||
let file_path = p.join(CGROUP_PROCS);
|
||||
if file_path.exists() {
|
||||
let file = File::open(file_path)?;
|
||||
for line in BufReader::new(file).lines() {
|
||||
if let Ok(line) = line {
|
||||
result.push(Pid::from_raw(line.parse::<i32>()?))
|
||||
}
|
||||
for line in BufReader::new(file).lines().flatten() {
|
||||
result.push(Pid::from_raw(line.parse::<i32>()?))
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -202,7 +200,7 @@ fn walk_dir<F>(path: &Path, c: &mut F) -> Result<()>
|
|||
where
|
||||
F: FnMut(&Path) -> Result<()>,
|
||||
{
|
||||
c(&path)?;
|
||||
c(path)?;
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
|
|
@ -365,8 +365,8 @@ mod tests {
|
|||
"Total 0",
|
||||
]
|
||||
.join("\n");
|
||||
set_fixture(&tmp, BLKIO_THROTTLE_IO_SERVICE_BYTES, &content).unwrap();
|
||||
set_fixture(&tmp, BLKIO_THROTTLE_IO_SERVICED, &content).unwrap();
|
||||
set_fixture(&tmp, BLKIO_THROTTLE_IO_SERVICE_BYTES, content).unwrap();
|
||||
set_fixture(&tmp, BLKIO_THROTTLE_IO_SERVICED, content).unwrap();
|
||||
|
||||
let actual = Blkio::stats(&tmp).expect("get cgroup stats");
|
||||
let mut expected = BlkioStats::default();
|
||||
|
|
|
@ -230,7 +230,7 @@ mod tests {
|
|||
"throttled_time 1080",
|
||||
]
|
||||
.join("\n");
|
||||
set_fixture(&tmp, CGROUP_CPU_STAT, &stat_content).expect("create stat file");
|
||||
set_fixture(&tmp, CGROUP_CPU_STAT, stat_content).expect("create stat file");
|
||||
|
||||
let actual = Cpu::stats(&tmp).expect("get cgroup stats");
|
||||
let expected = CpuThrottling {
|
||||
|
|
|
@ -24,7 +24,7 @@ impl Controller for Devices {
|
|||
]
|
||||
.concat()
|
||||
{
|
||||
Self::apply_device(&d, &cgroup_root)?;
|
||||
Self::apply_device(&d, cgroup_root)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -120,7 +120,7 @@ mod tests {
|
|||
set_fixture(&tmp, "devices.allow", "").expect("create allowed devices list");
|
||||
set_fixture(&tmp, "devices.deny", "").expect("create denied devices list");
|
||||
|
||||
Devices::apply_device(&d, &tmp).expect("Apply default device");
|
||||
Devices::apply_device(d, &tmp).expect("Apply default device");
|
||||
println!("Device: {}", d.to_string());
|
||||
if d.allow {
|
||||
let allowed_content =
|
||||
|
@ -172,7 +172,7 @@ mod tests {
|
|||
set_fixture(&tmp, "devices.allow", "").expect("create allowed devices list");
|
||||
set_fixture(&tmp, "devices.deny", "").expect("create denied devices list");
|
||||
|
||||
Devices::apply_device(&d, &tmp).expect("Apply default device");
|
||||
Devices::apply_device(d, &tmp).expect("Apply default device");
|
||||
println!("Device: {}", d.to_string());
|
||||
if d.allow {
|
||||
let allowed_content =
|
||||
|
@ -209,7 +209,7 @@ mod tests {
|
|||
.map(|device| {
|
||||
set_fixture(&tmp, "devices.allow", "").expect("create allowed devices list");
|
||||
set_fixture(&tmp, "devices.deny", "").expect("create denied devices list");
|
||||
Devices::apply_device(&device, &tmp).expect("Apply default device");
|
||||
Devices::apply_device(device, &tmp).expect("Apply default device");
|
||||
if device.allow {
|
||||
let allowed_content =
|
||||
read_to_string(tmp.join("devices.allow")).expect("read to string");
|
||||
|
|
|
@ -53,7 +53,7 @@ impl Manager {
|
|||
let p = if cgroup_path.to_string_lossy().into_owned().is_empty() {
|
||||
mount_point.join_absolute_path(Path::new(&cgroup.pathname))?
|
||||
} else if cgroup_path.is_absolute() {
|
||||
mount_point.join_absolute_path(&cgroup_path)?
|
||||
mount_point.join_absolute_path(cgroup_path)?
|
||||
} else {
|
||||
mount_point.join(cgroup_path)
|
||||
};
|
||||
|
@ -133,20 +133,18 @@ impl CgroupManager for Manager {
|
|||
fn apply(&self, linux_resources: &LinuxResources) -> Result<()> {
|
||||
for subsys in self.get_required_controllers(linux_resources)? {
|
||||
match subsys.0 {
|
||||
CtrlType::Cpu => Cpu::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::CpuAcct => CpuAcct::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::CpuSet => CpuSet::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::Devices => Devices::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::HugeTlb => Hugetlb::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::Memory => Memory::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::Pids => Pids::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::PerfEvent => PerfEvent::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::Blkio => Blkio::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::NetworkPriority => NetworkPriority::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::NetworkClassifier => {
|
||||
NetworkClassifier::apply(linux_resources, &subsys.1)?
|
||||
}
|
||||
CtrlType::Freezer => Freezer::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::Cpu => Cpu::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::CpuAcct => CpuAcct::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::CpuSet => CpuSet::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::Devices => Devices::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::HugeTlb => Hugetlb::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::Memory => Memory::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::Pids => Pids::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::PerfEvent => PerfEvent::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::Blkio => Blkio::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::NetworkPriority => NetworkPriority::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::NetworkClassifier => NetworkClassifier::apply(linux_resources, subsys.1)?,
|
||||
CtrlType::Freezer => Freezer::apply(linux_resources, subsys.1)?,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,7 +177,7 @@ impl CgroupManager for Manager {
|
|||
};
|
||||
Freezer::apply(
|
||||
&linux_resources,
|
||||
&self.subsystems.get(&CtrlType::Freezer).unwrap(),
|
||||
self.subsystems.get(&CtrlType::Freezer).unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ impl Controller for Memory {
|
|||
if let Some(memory) = Self::needs_to_handle(linux_resources) {
|
||||
let reservation = memory.reservation.unwrap_or(0);
|
||||
|
||||
Self::apply(&memory, cgroup_root)?;
|
||||
Self::apply(memory, cgroup_root)?;
|
||||
|
||||
if reservation != 0 {
|
||||
common::write_cgroup_file(
|
||||
|
|
|
@ -33,7 +33,7 @@ impl Controller for NetworkPriority {
|
|||
impl NetworkPriority {
|
||||
fn apply(root_path: &Path, network: &LinuxNetwork) -> Result<()> {
|
||||
let priorities: String = network.priorities.iter().map(|p| p.to_string()).collect();
|
||||
common::write_cgroup_file_str(root_path.join("net_prio.ifpriomap"), &priorities.trim())?;
|
||||
common::write_cgroup_file_str(root_path.join("net_prio.ifpriomap"), priorities.trim())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ impl Ps {
|
|||
println!("{}", std::str::from_utf8(&output.stderr)?);
|
||||
} else {
|
||||
let lines = std::str::from_utf8(&output.stdout)?;
|
||||
let lines: Vec<&str> = lines.split("\n").collect();
|
||||
let lines: Vec<&str> = lines.split('\n').collect();
|
||||
let pid_index = get_pid_index(lines[0])?;
|
||||
println!("{}", &lines[0]);
|
||||
for line in &lines[1..] {
|
||||
|
|
|
@ -98,7 +98,7 @@ impl ContainerBuilderImpl {
|
|||
|
||||
cmanager.add_task(init_pid)?;
|
||||
if self.rootless.is_none() && linux.resources.is_some() && self.init {
|
||||
cmanager.apply(&linux.resources.as_ref().unwrap())?;
|
||||
cmanager.apply(linux.resources.as_ref().unwrap())?;
|
||||
}
|
||||
|
||||
// if file to write the pid to is specified, write pid of the child
|
||||
|
@ -191,7 +191,7 @@ fn container_init(args: ContainerInitArgs) -> Result<()> {
|
|||
// join existing namespaces
|
||||
namespaces.apply_setns()?;
|
||||
|
||||
command.set_hostname(&spec.hostname.as_ref().context("no hostname in spec")?)?;
|
||||
command.set_hostname(spec.hostname.as_ref().context("no hostname in spec")?)?;
|
||||
|
||||
if proc.no_new_privileges {
|
||||
let _ = prctl::set_no_new_privileges(true);
|
||||
|
@ -199,8 +199,8 @@ fn container_init(args: ContainerInitArgs) -> Result<()> {
|
|||
|
||||
if args.init {
|
||||
rootfs::prepare_rootfs(
|
||||
&spec,
|
||||
&rootfs,
|
||||
spec,
|
||||
rootfs,
|
||||
namespaces
|
||||
.clone_flags
|
||||
.contains(sched::CloneFlags::CLONE_NEWUSER),
|
||||
|
@ -216,7 +216,7 @@ fn container_init(args: ContainerInitArgs) -> Result<()> {
|
|||
command.set_id(Uid::from_raw(proc.user.uid), Gid::from_raw(proc.user.gid))?;
|
||||
capabilities::reset_effective(command)?;
|
||||
if let Some(caps) = &proc.capabilities {
|
||||
capabilities::drop_privileges(&caps, command)?;
|
||||
capabilities::drop_privileges(caps, command)?;
|
||||
}
|
||||
|
||||
// notify parents that the init process is ready to execute the payload.
|
||||
|
|
|
@ -112,7 +112,7 @@ impl InitContainerBuilder {
|
|||
ContainerStatus::Creating,
|
||||
None,
|
||||
self.bundle.as_path().to_str().unwrap(),
|
||||
&container_dir,
|
||||
container_dir,
|
||||
)?;
|
||||
container.save()?;
|
||||
Ok(container)
|
||||
|
|
|
@ -301,14 +301,14 @@ impl TenantContainerBuilder {
|
|||
}
|
||||
|
||||
fn setup_notify_listener(container_dir: &Path) -> Result<PathBuf> {
|
||||
let notify_name = Self::generate_name(&container_dir, TENANT_NOTIFY);
|
||||
let notify_name = Self::generate_name(container_dir, TENANT_NOTIFY);
|
||||
let socket_path = container_dir.join(¬ify_name);
|
||||
|
||||
Ok(socket_path)
|
||||
}
|
||||
|
||||
fn setup_tty_socket(&self, container_dir: &Path) -> Result<Option<FileDescriptor>> {
|
||||
let tty_name = Self::generate_name(&container_dir, TENANT_TTY);
|
||||
let tty_name = Self::generate_name(container_dir, TENANT_TTY);
|
||||
let csocketfd = if let Some(console_socket) = &self.base.console_socket {
|
||||
Some(tty::setup_console_socket(
|
||||
container_dir,
|
||||
|
|
|
@ -34,23 +34,23 @@ pub fn prepare_rootfs(spec: &Spec, rootfs: &Path, bind_devices: bool) -> Result<
|
|||
|
||||
log::debug!("mount root fs {:?}", rootfs);
|
||||
nix_mount::<Path, Path, str, str>(
|
||||
Some(&rootfs),
|
||||
&rootfs,
|
||||
Some(rootfs),
|
||||
rootfs,
|
||||
None::<&str>,
|
||||
MsFlags::MS_BIND | MsFlags::MS_REC,
|
||||
None::<&str>,
|
||||
)?;
|
||||
|
||||
for m in spec.mounts.as_ref().context("no mounts in spec")?.iter() {
|
||||
let (flags, data) = parse_mount(&m);
|
||||
let (flags, data) = parse_mount(m);
|
||||
let ml = &linux.mount_label;
|
||||
if m.typ == "cgroup" {
|
||||
// skip
|
||||
log::warn!("A feature of cgroup is unimplemented.");
|
||||
} else if m.destination == PathBuf::from("/dev") {
|
||||
mount_to_container(&m, rootfs, flags & !MsFlags::MS_RDONLY, &data, &ml)?;
|
||||
mount_to_container(m, rootfs, flags & !MsFlags::MS_RDONLY, &data, ml)?;
|
||||
} else {
|
||||
mount_to_container(&m, rootfs, flags, &data, &ml)?;
|
||||
mount_to_container(m, rootfs, flags, &data, ml)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn detect_rootless(spec: &Spec) -> Result<Option<Rootless>> {
|
|||
validate(spec)?;
|
||||
let linux = spec.linux.as_ref().context("no linux in spec")?;
|
||||
let mut rootless = Rootless::from(linux);
|
||||
if let Some((uid_binary, gid_binary)) = lookup_map_binaries(&linux)? {
|
||||
if let Some((uid_binary, gid_binary)) = lookup_map_binaries(linux)? {
|
||||
rootless.newuidmap = Some(uid_binary);
|
||||
rootless.newgidmap = Some(gid_binary);
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ mod tests {
|
|||
let (testdir, rundir_path, socket_path) = init.unwrap();
|
||||
let lis = UnixListener::bind(Path::join(&testdir, "console-socket"));
|
||||
assert!(lis.is_ok());
|
||||
let fd = setup_console_socket(&&rundir_path, &socket_path, CONSOLE_SOCKET);
|
||||
let fd = setup_console_socket(&rundir_path, &socket_path, CONSOLE_SOCKET);
|
||||
assert!(fd.is_ok());
|
||||
assert_ne!(fd.unwrap().as_raw_fd(), -1);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ mod tests {
|
|||
let (testdir, rundir_path, socket_path) = init.unwrap();
|
||||
let lis = UnixListener::bind(Path::join(&testdir, "console-socket"));
|
||||
assert!(lis.is_ok());
|
||||
let fd = setup_console_socket(&&rundir_path, &socket_path, CONSOLE_SOCKET);
|
||||
let fd = setup_console_socket(&rundir_path, &socket_path, CONSOLE_SOCKET);
|
||||
let status = setup_console(&fd.unwrap());
|
||||
assert!(status.is_ok());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue