From 121111b8648994c94d81cc03a91c445f2e1a45e5 Mon Sep 17 00:00:00 2001 From: csf Date: Wed, 7 Sep 2022 20:08:12 +0800 Subject: [PATCH] add flutter start_server & fix cm user environment from linux service --- src/core_main.rs | 12 ++++++++++-- src/platform/linux.rs | 27 +++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index c780a1cb0..02ac5e646 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -1,6 +1,6 @@ use hbb_common::log; -use crate::{start_os_service, flutter::connection_manager}; +use crate::{start_os_service, flutter::connection_manager, start_server}; /// Main entry of the RustDesk Core. /// Return true if the app should continue running with UI(possibly Flutter), false if the app should exit. @@ -20,7 +20,15 @@ pub fn core_main() -> bool { return false; } if args[1] == "--server" { - // TODO: server + log::info!("start --server"); + #[cfg(not(target_os = "macos"))] + { + start_server(true); + } + #[cfg(target_os = "macos")] + { + std::thread::spawn(move || start_server(true)); + } return false; } } diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 0ead52f31..fe2673832 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -525,20 +525,27 @@ pub fn is_root() -> bool { crate::username() == "root" } +fn is_opensuse() -> bool { + if let Ok(res) = run_cmds("cat /etc/os-release | grep opensuse".to_owned()) { + if !res.is_empty() { + return true; + } + } + false +} + pub fn run_as_user(arg: &str) -> ResultType> { let uid = get_active_userid(); let cmd = std::env::current_exe()?; + let xdg = &format!("XDG_RUNTIME_DIR=/run/user/{}", uid) as &str; + let username = &get_active_username(); + let mut args = vec![xdg, "-u", username, cmd.to_str().unwrap_or(""), arg]; // -E required for opensuse - let task = std::process::Command::new("sudo") - .args(vec![ - "-E", - &format!("XDG_RUNTIME_DIR=/run/user/{}", uid) as &str, - "-u", - &get_active_username(), - cmd.to_str().unwrap_or(""), - arg, - ]) - .spawn()?; + if is_opensuse() { + args.insert(0, "-E"); + } + + let task = std::process::Command::new("sudo").args(args).spawn()?; Ok(Some(task)) }