Skip to content

Commit

Permalink
slot-ctrl: remove two lines of unsafe (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah authored Nov 14, 2024
1 parent e4c8de1 commit b3dbbe4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ libc = "0.2.153"
nix = { version = "0.28", default-features = false, features = [] }
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "stream"] }
ring = "0.16"
rustix = "0.38.37"
secrecy = "0.8"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1"
Expand Down
7 changes: 7 additions & 0 deletions slot-ctrl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ orb-build-info.path = "../build-info"
thiserror.workspace = true
tempfile = "3.12.0"

[dependencies.rustix]
workspace = true
features = [
"fs",
"process",
]

[build-dependencies]
orb-build-info = { path = "../build-info", features = ["build-script"] }

Expand Down
3 changes: 2 additions & 1 deletion slot-ctrl/src/efivar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! [efivar Documentation](https://www.kernel.org/doc/html/latest/filesystems/efivarfs.html)

use std::{
ffi::c_int,
fs::{self, File},
io::{self, Read, Write},
path::{Path, PathBuf},
Expand Down Expand Up @@ -109,7 +110,7 @@ impl EfiVar {
let file_read =
File::open(&self.path).map_err(|e| Error::open_file(&self.path, e))?;

let original_attributes: libc::c_int =
let original_attributes: c_int =
ioctl::read_file_attributes(&file_read).map_err(Error::GetAttributes)?;

// Make file mutable.
Expand Down
6 changes: 3 additions & 3 deletions slot-ctrl/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ enum StatusCommands {
}

fn check_running_as_root(error: crate::Error) {
let uid = unsafe { libc::getuid() };
let euid = unsafe { libc::geteuid() };
if !matches!((uid, euid), (0, 0)) {
let uid = rustix::process::getuid();
let euid = rustix::process::geteuid();
if !(uid.is_root() && euid.is_root()) {
println!("Please try again as root user.");
exit(1)
}
Expand Down

0 comments on commit b3dbbe4

Please sign in to comment.