run_as_user use vec arg

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-11-27 12:31:53 +08:00
parent 99f41007e9
commit 51cfa6f666
4 changed files with 17 additions and 18 deletions

View File

@@ -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<Option<std::process::Child>> {
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");