diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 8c0df67dd..c8abe432e 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -324,7 +324,7 @@ pub fn start_os_service() { ) { stop_rustdesk_servers(); std::thread::sleep(std::time::Duration::from_millis(super::SERVICE_INTERVAL)); - match run_as_user("--server", Some((cur_uid, cur_user))) { + match run_as_user(vec!["--server"], Some((cur_uid, cur_user))) { Ok(ps) => user_server = ps, Err(err) => { log::error!("Failed to start server: {}", err); @@ -566,7 +566,7 @@ fn is_opensuse() -> bool { } pub fn run_as_user( - arg: &str, + arg: Vec<&str>, user: Option<(String, String)>, ) -> ResultType> { let (uid, username) = match user { @@ -575,7 +575,8 @@ pub fn run_as_user( }; let cmd = std::env::current_exe()?; let xdg = &format!("XDG_RUNTIME_DIR=/run/user/{}", uid) as &str; - let mut args = vec![xdg, "-u", &username, cmd.to_str().unwrap_or(""), arg]; + let mut args = vec![xdg, "-u", &username, cmd.to_str().unwrap_or("")]; + args.append(&mut arg.clone()); // -E required for opensuse if is_opensuse() { args.insert(0, "-E"); diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 9a474321e..edb2aadb1 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -394,12 +394,12 @@ pub fn is_root() -> bool { crate::username() == "root" } -pub fn run_as_user(arg: &str) -> ResultType> { +pub fn run_as_user(arg: Vec<&str>) -> ResultType> { let uid = get_active_userid(); let cmd = std::env::current_exe()?; - let task = std::process::Command::new("launchctl") - .args(vec!["asuser", &uid, cmd.to_str().unwrap_or(""), arg]) - .spawn()?; + let mut args = vec!["asuser", &uid, cmd.to_str().unwrap_or("")]; + args.append(&mut arg.clone()); + let task = std::process::Command::new("launchctl").args(args).spawn()?; Ok(Some(task)) } @@ -538,7 +538,6 @@ pub fn quit_gui() { }; } - pub fn get_double_click_time() -> u32 { // to-do: https://github.com/servo/core-foundation-rs/blob/786895643140fa0ee4f913d7b4aeb0c4626b2085/cocoa/src/appkit.rs#L2823 500 as _ diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 19c092f29..075f7ed08 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -580,11 +580,11 @@ async fn launch_server(session_id: DWORD, close_first: bool) -> ResultType ResultType> { +pub fn run_as_user(arg: Vec<&str>) -> ResultType> { let cmd = format!( "\"{}\" {}", std::env::current_exe()?.to_str().unwrap_or(""), - arg, + arg.join(" "), ); let session_id = unsafe { get_current_session(share_rdp()) }; use std::os::windows::ffi::OsStrExt; @@ -596,7 +596,7 @@ pub fn run_as_user(arg: &str) -> ResultType> { let h = unsafe { LaunchProcessWin(wstr, session_id, TRUE) }; if h.is_null() { bail!( - "Failed to launch {} with session id {}: {}", + "Failed to launch {:?} with session id {}: {}", arg, session_id, get_error() diff --git a/src/server/connection.rs b/src/server/connection.rs index 249dadc5e..fb281adde 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -1571,18 +1571,21 @@ async fn start_ipc( if let Ok(s) = crate::ipc::connect(1000, "_cm").await { stream = Some(s); } else { - let extra_args = if password::hide_cm() { "--hide" } else { "" }; + let mut args = vec!["--cm"]; + if password::hide_cm() { + args.push("--hide"); + }; let run_done; if crate::platform::is_root() { let mut res = Ok(None); for _ in 0..10 { #[cfg(not(target_os = "linux"))] { - res = crate::platform::run_as_user(&format!("--cm {}", extra_args)); + res = crate::platform::run_as_user(args.clone()); } #[cfg(target_os = "linux")] { - res = crate::platform::run_as_user(&format!("--cm {}", extra_args), None); + res = crate::platform::run_as_user(args.clone(), None); } if res.is_ok() { break; @@ -1597,10 +1600,6 @@ async fn start_ipc( run_done = false; } if !run_done { - let mut args = vec!["--cm"]; - if !extra_args.is_empty() { - args.push(&extra_args); - } super::CHILD_PROCESS .lock() .unwrap()