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