diff --git a/src/platform/linux.rs b/src/platform/linux.rs index db37d573a..78e539923 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -17,7 +17,8 @@ use hbb_common::{ use std::{ cell::RefCell, ffi::OsStr, - io::Write, + fs::File, + io::{BufRead, BufReader, Write}, path::{Path, PathBuf}, process::{Child, Command}, string::String, @@ -216,6 +217,9 @@ fn try_start_server_(desktop: Option<&Desktop>) -> ResultType> { if !desktop.wl_display.is_empty() { envs.push(("WAYLAND_DISPLAY", desktop.wl_display.clone())); } + if !desktop.home.is_empty() { + envs.push(("HOME", desktop.home.clone())); + } run_as_user( vec!["--server"], Some((desktop.uid.clone(), desktop.username.clone())), @@ -378,7 +382,7 @@ pub fn start_os_service() { // Duplicate logic here with should_start_server // Login wayland will try to start a headless --server. - if desktop.username == "root" || !desktop.is_wayland() || desktop.is_login_wayland() { + if desktop.username == "root" || desktop.is_login_wayland() { // try kill subprocess "--server" stop_server(&mut user_server); // try start subprocess "--server" @@ -406,7 +410,7 @@ pub fn start_os_service() { // try start subprocess "--server" if should_start_server( - false, + !desktop.is_wayland(), is_display_changed, &mut uid, &desktop, @@ -592,7 +596,7 @@ where let mut args = vec![xdg, "-u", &username, cmd.to_str().unwrap_or("")]; args.append(&mut arg.clone()); // -E is required to preserve env - args.insert(0, "-E"); + args.insert(0, "-E"); let task = Command::new("sudo").envs(envs).args(args).spawn()?; Ok(Some(task)) @@ -924,7 +928,7 @@ mod desktop { const XWAYLAND: &str = "Xwayland"; const IBUS_DAEMON: &str = "ibus-daemon"; - const PLASMA_KDED5: &str = "kded5"; + const PLASMA_KDED: &str = "kded[0-9]+"; const GNOME_GOA_DAEMON: &str = "goa-daemon"; const RUSTDESK_TRAY: &str = "rustdesk +--tray"; @@ -936,6 +940,7 @@ mod desktop { pub protocal: String, pub display: String, pub xauth: String, + pub home: String, pub is_rustdesk_subprocess: bool, pub wl_display: String, } @@ -962,7 +967,7 @@ mod desktop { XWAYLAND, IBUS_DAEMON, GNOME_GOA_DAEMON, - PLASMA_KDED5, + PLASMA_KDED, RUSTDESK_TRAY, ]; for proc in display_proc { @@ -983,7 +988,7 @@ mod desktop { XWAYLAND, IBUS_DAEMON, GNOME_GOA_DAEMON, - PLASMA_KDED5, + PLASMA_KDED, XFCE4_PANEL, SDDM_GREETER, ]; @@ -1008,6 +1013,16 @@ mod desktop { .replace("localhost", ""); } + fn get_home(&mut self) { + self.home = "".to_string(); + + let cmd = format!( + "getent passwd '{}' | awk -F':' '{{print $6}}'", + &self.username + ); + self.home = run_cmds(&cmd).unwrap_or(format!("/home/{}", &self.username)); + } + fn get_xauth_from_xorg(&mut self) { if let Ok(output) = run_cmds(&format!( "ps -u {} -f | grep 'Xorg' | grep -v 'grep'", @@ -1056,9 +1071,10 @@ mod desktop { XWAYLAND, IBUS_DAEMON, GNOME_GOA_DAEMON, - PLASMA_KDED5, + PLASMA_KDED, XFCE4_PANEL, SDDM_GREETER, + RUSTDESK_TRAY, ]; for proc in display_proc { self.xauth = get_env("XAUTHORITY", &self.uid, proc); @@ -1179,6 +1195,7 @@ mod desktop { return; } + self.get_home(); if self.is_wayland() { if is_xwayland_running() { self.get_display_xauth_xwayland();