amethyst: wrap root check in a safe wrapper

i18n
Fries 2 years ago
parent a0534b117d
commit b4d02e8ab1

@ -93,3 +93,8 @@ pub fn wrap_text<S: AsRef<str>>(s: S, padding: usize) -> Vec<String> {
.map(String::from) .map(String::from)
.collect() .collect()
} }
pub fn is_run_with_root() -> bool {
let uid = unsafe { libc::geteuid() };
uid == 0
}

@ -3,8 +3,8 @@ use builder::pacman::{PacmanColor, PacmanQueryBuilder};
use clap::Parser; use clap::Parser;
use internal::commands::ShellCommand; use internal::commands::ShellCommand;
use internal::detect;
use internal::error::SilentUnwrap; use internal::error::SilentUnwrap;
use internal::{detect, utils};
use crate::args::{InstallArgs, Operation, QueryArgs, RemoveArgs}; use crate::args::{InstallArgs, Operation, QueryArgs, RemoveArgs};
use crate::interact::page_string; use crate::interact::page_string;
@ -32,7 +32,7 @@ use logging::init_logger;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
color_eyre::install().unwrap(); color_eyre::install().unwrap();
if unsafe { libc::geteuid() } == 0 { if utils::is_run_with_root() {
fl_crash!(AppExitCode::RunAsRoot, "run-as-root"); fl_crash!(AppExitCode::RunAsRoot, "run-as-root");
} }

Loading…
Cancel
Save