From 4376b8efbffa1a12f84d162a67ee0fa236fb0444 Mon Sep 17 00:00:00 2001 From: michal Date: Tue, 18 Jan 2022 19:19:07 +0000 Subject: [PATCH] superuser check + infersubcommands --- src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index baa9e8b..56daa13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,14 @@ use clap::{App, AppSettings, Arg, ArgSettings, SubCommand}; use std::process::exit; fn main() { + extern "C" { + fn geteuid() -> u32; + } + + if unsafe { geteuid() } == 0 { + panic!("Running amethyst as root is disallowed as it can lead to system breakage. Instead, amethyst will prompt you when it needs superuser permissions.") + } + let matches = App::new("Amethyst") .version(env!("CARGO_PKG_VERSION")) .about(env!("CARGO_PKG_DESCRIPTION")) @@ -81,6 +89,7 @@ fn main() { AppSettings::GlobalVersion, AppSettings::VersionlessSubcommands, AppSettings::ArgRequiredElseHelp, + AppSettings::InferSubcommands, ]) .get_matches();