refact, linux headless option, debug
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
c0ead118a2
commit
55972bfac5
@ -91,7 +91,7 @@ pub const LOGIN_MSG_PASSWORD_WRONG: &str = "Wrong Password";
|
||||
pub const LOGIN_MSG_NO_PASSWORD_ACCESS: &str = "No Password Access";
|
||||
pub const LOGIN_MSG_OFFLINE: &str = "Offline";
|
||||
#[cfg(target_os = "linux")]
|
||||
pub const LOGIN_SCREEN_WAYLAND: &str = "Wayland login screen";
|
||||
pub const LOGIN_SCREEN_WAYLAND: &str = "Wayland login screen is not supported";
|
||||
#[cfg(target_os = "linux")]
|
||||
pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version.";
|
||||
#[cfg(target_os = "linux")]
|
||||
|
@ -1,5 +1,8 @@
|
||||
use super::{CursorData, ResultType};
|
||||
use desktop::Desktop;
|
||||
#[cfg(all(feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
use hbb_common::config::CONFIG_OPTION_ALLOW_LINUX_HEADLESS;
|
||||
pub use hbb_common::platform::linux::*;
|
||||
use hbb_common::{
|
||||
allow_err, bail,
|
||||
@ -9,9 +12,6 @@ use hbb_common::{
|
||||
message_proto::Resolution,
|
||||
regex::{Captures, Regex},
|
||||
};
|
||||
#[cfg(all(feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
use hbb_common::config::CONFIG_OPTION_ALLOW_LINUX_HEADLESS;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
io::Write,
|
||||
@ -439,13 +439,21 @@ fn get_cm() -> bool {
|
||||
}
|
||||
|
||||
pub fn is_login_wayland() -> bool {
|
||||
if let Ok(contents) = std::fs::read_to_string("/etc/gdm3/custom.conf") {
|
||||
contents.contains("#WaylandEnable=false") || contents.contains("WaylandEnable=true")
|
||||
} else if let Ok(contents) = std::fs::read_to_string("/etc/gdm/custom.conf") {
|
||||
contents.contains("#WaylandEnable=false") || contents.contains("WaylandEnable=true")
|
||||
} else {
|
||||
false
|
||||
let files = ["/etc/gdm3/custom.conf", "/etc/gdm/custom.conf"];
|
||||
match (
|
||||
Regex::new(r"# *WaylandEnable *= *false"),
|
||||
Regex::new(r"WaylandEnable *= *true"),
|
||||
) {
|
||||
(Ok(pat1), Ok(pat2)) => {
|
||||
for file in files {
|
||||
if let Ok(contents) = std::fs::read_to_string(file) {
|
||||
return pat1.is_match(&contents) || pat2.is_match(&contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -109,7 +109,7 @@ pub fn try_start_desktop(_username: &str, _passsword: &str) -> String {
|
||||
// No need to verify password here.
|
||||
return "".to_owned();
|
||||
}
|
||||
if username.is_empty() {
|
||||
if !username.is_empty() {
|
||||
// Another user is logged in. No need to start a new xsession.
|
||||
return "".to_owned();
|
||||
}
|
||||
|
@ -73,11 +73,10 @@ impl RendezvousMediator {
|
||||
allow_err!(super::lan::start_listening());
|
||||
});
|
||||
}
|
||||
// It is ok to run xdesktop manager when the headless function is not allowed.
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
if crate::platform::is_headless_allowed() {
|
||||
crate::platform::linux_desktop_manager::start_xdesktop();
|
||||
}
|
||||
crate::platform::linux_desktop_manager::start_xdesktop();
|
||||
loop {
|
||||
Config::reset_online();
|
||||
if Config::get_option("stop-service").is_empty() {
|
||||
|
@ -1386,6 +1386,12 @@ impl Connection {
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
let is_headless_allowed = crate::platform::is_headless_allowed();
|
||||
#[cfg(any(
|
||||
feature = "flatpak",
|
||||
feature = "appimage",
|
||||
not(all(target_os = "linux", feature = "linux_headless"))
|
||||
))]
|
||||
let is_headless_allowed = false;
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
let desktop_err = if is_headless_allowed {
|
||||
@ -1406,20 +1412,10 @@ impl Connection {
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
let wait_ipc_timeout = 10_000;
|
||||
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
let is_headless_proc = is_headless_allowed;
|
||||
#[cfg(any(
|
||||
feature = "flatpak",
|
||||
feature = "appimage",
|
||||
not(all(target_os = "linux", feature = "linux_headless"))
|
||||
))]
|
||||
let is_headless_proc = false;
|
||||
|
||||
// If err is LOGIN_MSG_DESKTOP_SESSION_NOT_READY, just keep this msg and go on checking password.
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
if is_headless_proc
|
||||
if is_headless_allowed
|
||||
&& !desktop_err.is_empty()
|
||||
&& desktop_err != crate::client::LOGIN_MSG_DESKTOP_SESSION_NOT_READY
|
||||
{
|
||||
@ -1453,7 +1449,7 @@ impl Connection {
|
||||
} else if self.is_recent_session() {
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
if is_headless_proc {
|
||||
if is_headless_allowed {
|
||||
if desktop_err.is_empty() {
|
||||
if is_headless {
|
||||
self.tx_desktop_ready.send(()).await.ok();
|
||||
@ -1469,7 +1465,7 @@ impl Connection {
|
||||
self.send_login_error(desktop_err).await;
|
||||
}
|
||||
}
|
||||
if !is_headless_proc {
|
||||
if !is_headless_allowed {
|
||||
self.try_start_cm(lr.my_id, lr.my_name, true);
|
||||
self.send_logon_response().await;
|
||||
if self.port_forward_socket.is_some() {
|
||||
@ -1479,7 +1475,7 @@ impl Connection {
|
||||
} else if lr.password.is_empty() {
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
if is_headless_proc {
|
||||
if is_headless_allowed {
|
||||
if desktop_err.is_empty() {
|
||||
self.try_start_cm(lr.my_id.clone(), lr.my_name.clone(), false);
|
||||
} else {
|
||||
@ -1489,7 +1485,7 @@ impl Connection {
|
||||
.await;
|
||||
}
|
||||
}
|
||||
if !is_headless_proc {
|
||||
if !is_headless_allowed {
|
||||
self.try_start_cm(lr.my_id, lr.my_name, false);
|
||||
}
|
||||
} else {
|
||||
@ -1532,7 +1528,7 @@ impl Connection {
|
||||
.insert(self.ip.clone(), failure);
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
if is_headless_proc {
|
||||
if is_headless_allowed {
|
||||
if desktop_err.is_empty() {
|
||||
self.send_login_error(crate::client::LOGIN_MSG_PASSWORD_WRONG)
|
||||
.await;
|
||||
@ -1544,7 +1540,7 @@ impl Connection {
|
||||
.await;
|
||||
}
|
||||
}
|
||||
if !is_headless_proc {
|
||||
if !is_headless_allowed {
|
||||
self.send_login_error(crate::client::LOGIN_MSG_PASSWORD_WRONG)
|
||||
.await;
|
||||
self.try_start_cm(lr.my_id, lr.my_name, false);
|
||||
@ -1555,7 +1551,7 @@ impl Connection {
|
||||
}
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
if is_headless_proc {
|
||||
if is_headless_allowed {
|
||||
if desktop_err.is_empty() {
|
||||
if is_headless {
|
||||
self.tx_desktop_ready.send(()).await.ok();
|
||||
@ -1571,7 +1567,7 @@ impl Connection {
|
||||
self.send_login_error(desktop_err).await;
|
||||
}
|
||||
}
|
||||
if !is_headless_proc {
|
||||
if !is_headless_allowed {
|
||||
self.send_logon_response().await;
|
||||
self.try_start_cm(lr.my_id, lr.my_name, true);
|
||||
if self.port_forward_socket.is_some() {
|
||||
|
Loading…
Reference in New Issue
Block a user