mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor(linux): replace users crate with libc::geteuid for root detection
Closes #5333
This commit is contained in:
@@ -122,7 +122,6 @@ async fn reinstall_service() -> Result<()> {
|
||||
#[cfg(target_os = "linux")]
|
||||
async fn uninstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, "uninstall service");
|
||||
use users::get_effective_uid;
|
||||
|
||||
let uninstall_path =
|
||||
tauri::utils::platform::current_exe()?.with_file_name("clash-verge-service-uninstall");
|
||||
@@ -134,13 +133,14 @@ async fn uninstall_service() -> Result<()> {
|
||||
let uninstall_shell: String = uninstall_path.to_string_lossy().replace(" ", "\\ ");
|
||||
|
||||
let elevator = crate::utils::help::linux_elevator();
|
||||
let status = match get_effective_uid() {
|
||||
0 => StdCommand::new(uninstall_shell).status()?,
|
||||
_ => StdCommand::new(elevator)
|
||||
let status = if linux_running_as_root() {
|
||||
StdCommand::new(&uninstall_path).status()?
|
||||
} else {
|
||||
StdCommand::new(elevator)
|
||||
.arg("sh")
|
||||
.arg("-c")
|
||||
.arg(uninstall_shell)
|
||||
.status()?,
|
||||
.status()?
|
||||
};
|
||||
logging!(
|
||||
info,
|
||||
@@ -163,7 +163,6 @@ async fn uninstall_service() -> Result<()> {
|
||||
#[allow(clippy::unused_async)]
|
||||
async fn install_service() -> Result<()> {
|
||||
logging!(info, Type::Service, "install service");
|
||||
use users::get_effective_uid;
|
||||
|
||||
let install_path =
|
||||
tauri::utils::platform::current_exe()?.with_file_name("clash-verge-service-install");
|
||||
@@ -175,13 +174,14 @@ async fn install_service() -> Result<()> {
|
||||
let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ ");
|
||||
|
||||
let elevator = crate::utils::help::linux_elevator();
|
||||
let status = match get_effective_uid() {
|
||||
0 => StdCommand::new(install_shell).status()?,
|
||||
_ => StdCommand::new(elevator)
|
||||
let status = if linux_running_as_root() {
|
||||
StdCommand::new(&install_path).status()?
|
||||
} else {
|
||||
StdCommand::new(elevator)
|
||||
.arg("sh")
|
||||
.arg("-c")
|
||||
.arg(install_shell)
|
||||
.status()?,
|
||||
.status()?
|
||||
};
|
||||
logging!(
|
||||
info,
|
||||
@@ -218,6 +218,13 @@ async fn reinstall_service() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn linux_running_as_root() -> bool {
|
||||
const ROOT_UID: u32 = 0;
|
||||
|
||||
unsafe { libc::geteuid() == ROOT_UID }
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
async fn uninstall_service() -> Result<()> {
|
||||
use crate::utils::i18n::t;
|
||||
|
||||
Reference in New Issue
Block a user