Skip to content

Commit

Permalink
slot-ctrl: remove two lines of unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah committed Sep 30, 2024
1 parent b231361 commit 8bb323d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
35 changes: 18 additions & 17 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ console-subscriber = "0.2"
data-encoding = "2.3"
derive_more = { version = "0.99", default-features = false, features = ["display", "from"] }
eyre = "0.6.12"
ftdi-embedded-hal = { version = "0.22.0", features = ["libftd2xx", "libftd2xx-static"] }
futures = "0.3.30"
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 All @@ -67,7 +69,6 @@ tracing = "0.1"
tracing-journald = "0.3.0"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
zbus = { version = "4.4.0", default-features = false, features = ["tokio"] }
ftdi-embedded-hal = { version = "0.22.0", features = ["libftd2xx", "libftd2xx-static"] }
zbus_systemd = "0.25600.0"

can-rs.path = "can"
Expand Down
7 changes: 7 additions & 0 deletions orb-slot-ctrl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ libc.workspace = true
orb-build-info.path = "../build-info"
thiserror.workspace = true

[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 orb-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::File,
io::{Read, Write},
path::{Path, PathBuf},
Expand Down Expand Up @@ -79,7 +80,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 orb-slot-ctrl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ enum StatusCommands {
}

fn check_running_as_root(error: orb_slot_ctrl::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 8bb323d

Please sign in to comment.