refact, linux headless option, debug

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-07-29 15:22:25 +08:00
parent c0ead118a2
commit 55972bfac5
5 changed files with 36 additions and 33 deletions

View File

@ -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_NO_PASSWORD_ACCESS: &str = "No Password Access";
pub const LOGIN_MSG_OFFLINE: &str = "Offline"; pub const LOGIN_MSG_OFFLINE: &str = "Offline";
#[cfg(target_os = "linux")] #[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")] #[cfg(target_os = "linux")]
pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version."; pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version.";
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]

View File

@ -1,5 +1,8 @@
use super::{CursorData, ResultType}; use super::{CursorData, ResultType};
use desktop::Desktop; 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::*; pub use hbb_common::platform::linux::*;
use hbb_common::{ use hbb_common::{
allow_err, bail, allow_err, bail,
@ -9,9 +12,6 @@ use hbb_common::{
message_proto::Resolution, message_proto::Resolution,
regex::{Captures, Regex}, 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::{ use std::{
cell::RefCell, cell::RefCell,
io::Write, io::Write,
@ -439,13 +439,21 @@ fn get_cm() -> bool {
} }
pub fn is_login_wayland() -> bool { pub fn is_login_wayland() -> bool {
if let Ok(contents) = std::fs::read_to_string("/etc/gdm3/custom.conf") { let files = ["/etc/gdm3/custom.conf", "/etc/gdm/custom.conf"];
contents.contains("#WaylandEnable=false") || contents.contains("WaylandEnable=true") match (
} else if let Ok(contents) = std::fs::read_to_string("/etc/gdm/custom.conf") { Regex::new(r"# *WaylandEnable *= *false"),
contents.contains("#WaylandEnable=false") || contents.contains("WaylandEnable=true") Regex::new(r"WaylandEnable *= *true"),
} else { ) {
false (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] #[inline]

View File

@ -109,7 +109,7 @@ pub fn try_start_desktop(_username: &str, _passsword: &str) -> String {
// No need to verify password here. // No need to verify password here.
return "".to_owned(); return "".to_owned();
} }
if username.is_empty() { if !username.is_empty() {
// Another user is logged in. No need to start a new xsession. // Another user is logged in. No need to start a new xsession.
return "".to_owned(); return "".to_owned();
} }

View File

@ -73,11 +73,10 @@ impl RendezvousMediator {
allow_err!(super::lan::start_listening()); 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(all(target_os = "linux", feature = "linux_headless"))]
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[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 { loop {
Config::reset_online(); Config::reset_online();
if Config::get_option("stop-service").is_empty() { if Config::get_option("stop-service").is_empty() {

View File

@ -1386,6 +1386,12 @@ impl Connection {
#[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(all(target_os = "linux", feature = "linux_headless"))]
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))]
let is_headless_allowed = crate::platform::is_headless_allowed(); 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(all(target_os = "linux", feature = "linux_headless"))]
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))]
let desktop_err = if is_headless_allowed { let desktop_err = if is_headless_allowed {
@ -1406,20 +1412,10 @@ impl Connection {
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))]
let wait_ipc_timeout = 10_000; 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. // 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(all(target_os = "linux", feature = "linux_headless"))]
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))]
if is_headless_proc if is_headless_allowed
&& !desktop_err.is_empty() && !desktop_err.is_empty()
&& desktop_err != crate::client::LOGIN_MSG_DESKTOP_SESSION_NOT_READY && desktop_err != crate::client::LOGIN_MSG_DESKTOP_SESSION_NOT_READY
{ {
@ -1453,7 +1449,7 @@ impl Connection {
} else if self.is_recent_session() { } else if self.is_recent_session() {
#[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(all(target_os = "linux", feature = "linux_headless"))]
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))]
if is_headless_proc { if is_headless_allowed {
if desktop_err.is_empty() { if desktop_err.is_empty() {
if is_headless { if is_headless {
self.tx_desktop_ready.send(()).await.ok(); self.tx_desktop_ready.send(()).await.ok();
@ -1469,7 +1465,7 @@ impl Connection {
self.send_login_error(desktop_err).await; 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.try_start_cm(lr.my_id, lr.my_name, true);
self.send_logon_response().await; self.send_logon_response().await;
if self.port_forward_socket.is_some() { if self.port_forward_socket.is_some() {
@ -1479,7 +1475,7 @@ impl Connection {
} else if lr.password.is_empty() { } else if lr.password.is_empty() {
#[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(all(target_os = "linux", feature = "linux_headless"))]
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))]
if is_headless_proc { if is_headless_allowed {
if desktop_err.is_empty() { if desktop_err.is_empty() {
self.try_start_cm(lr.my_id.clone(), lr.my_name.clone(), false); self.try_start_cm(lr.my_id.clone(), lr.my_name.clone(), false);
} else { } else {
@ -1489,7 +1485,7 @@ impl Connection {
.await; .await;
} }
} }
if !is_headless_proc { if !is_headless_allowed {
self.try_start_cm(lr.my_id, lr.my_name, false); self.try_start_cm(lr.my_id, lr.my_name, false);
} }
} else { } else {
@ -1532,7 +1528,7 @@ impl Connection {
.insert(self.ip.clone(), failure); .insert(self.ip.clone(), failure);
#[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(all(target_os = "linux", feature = "linux_headless"))]
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))]
if is_headless_proc { if is_headless_allowed {
if desktop_err.is_empty() { if desktop_err.is_empty() {
self.send_login_error(crate::client::LOGIN_MSG_PASSWORD_WRONG) self.send_login_error(crate::client::LOGIN_MSG_PASSWORD_WRONG)
.await; .await;
@ -1544,7 +1540,7 @@ impl Connection {
.await; .await;
} }
} }
if !is_headless_proc { if !is_headless_allowed {
self.send_login_error(crate::client::LOGIN_MSG_PASSWORD_WRONG) self.send_login_error(crate::client::LOGIN_MSG_PASSWORD_WRONG)
.await; .await;
self.try_start_cm(lr.my_id, lr.my_name, false); 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(all(target_os = "linux", feature = "linux_headless"))]
#[cfg(not(any(feature = "flatpak", feature = "appimage")))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))]
if is_headless_proc { if is_headless_allowed {
if desktop_err.is_empty() { if desktop_err.is_empty() {
if is_headless { if is_headless {
self.tx_desktop_ready.send(()).await.ok(); self.tx_desktop_ready.send(()).await.ok();
@ -1571,7 +1567,7 @@ impl Connection {
self.send_login_error(desktop_err).await; self.send_login_error(desktop_err).await;
} }
} }
if !is_headless_proc { if !is_headless_allowed {
self.send_logon_response().await; self.send_logon_response().await;
self.try_start_cm(lr.my_id, lr.my_name, true); self.try_start_cm(lr.my_id, lr.my_name, true);
if self.port_forward_socket.is_some() { if self.port_forward_socket.is_some() {