Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slot-ctrl: remove two lines of unsafe #246

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading