From 94b7936f5122d90250da6a7db77dc6c4f4b666d9 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 2 Nov 2021 16:32:04 +1100 Subject: [PATCH] agent/device: Use nix::sys::stat::{major,minor} instead of libc::* update_spec_devices() includes an unsafe block, in order to call the libc functions to get the major and minor numbers from a device ID. However, the nix crate already has a safe wrapper for this function, which we use in other places in the file. Signed-off-by: David Gibson --- src/agent/src/device.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index df0221c74..e01b7d3df 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -3,7 +3,6 @@ // SPDX-License-Identifier: Apache-2.0 // -use libc::{c_uint, major, minor}; use nix::sys::stat; use regex::Regex; use std::collections::HashMap; @@ -450,9 +449,6 @@ fn update_spec_device( vm_path: &str, final_path: &str, ) -> Result<()> { - let major_id: c_uint; - let minor_id: c_uint; - // If no container_path is provided, we won't be able to match and // update the device in the OCI spec device list. This is an error. if host_path.is_empty() { @@ -470,10 +466,8 @@ fn update_spec_device( let meta = fs::metadata(vm_path)?; let dev_id = meta.rdev(); - unsafe { - major_id = major(dev_id); - minor_id = minor(dev_id); - } + let major_id = stat::major(dev_id); + let minor_id = stat::minor(dev_id); info!( sl!(),