Fix/unix ipc auth (#17235)

* fix: verify Unix IPC endpoint and configuration sync peers

Check kernel peer credentials before dispatching main IPC messages. Verify the root service, the active user's main endpoint for management commands, and the process submitting service synchronization.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix: stop stale Linux GUIs and confirm Unix codec reports

Close the installed GUI before a package upgrade replaces its executable. Keep the codec probe alive until the installed Unix host reads back its report on the same IPC connection.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix: keep existing Linux package upgrade behavior

An Ubuntu upgrade from 1.5.0 to 1.5.3 on master already closed the main window. Drop the extra GUI termination from the Debian, RPM and Arch upgrade scripts to keep package lifecycle changes out of the IPC fix.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix: wait for Unix IPC peer verification before takeover

Keep an installed non-root server alive for a status round trip on the same main IPC connection before requesting the previous listener to close. This gives the listener time to verify the executable of the process requesting takeover.

Signed-off-by: fufesou <linlong1266@gmail.com>

* test: cover Unix service sync sender identity

Signed-off-by: fufesou <linlong1266@gmail.com>

* refact: function rename

Signed-off-by: fufesou <linlong1266@gmail.com>

* Refact: Remove unrachable branch

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix: wait for macOS main IPC verification before one-way sends

Keep the socket open until the listener replies to OnlineStatus. This lets the installed host resolve the sender PID before the GUI sends a password refresh or another one-way request.

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou authored and GitHub committed 2026-11-30 17:42:35 +08:00
1 parent 6cdf4412c9
commit 38e00b622f
5 files changed
+366 -37

No files matched your search

+153 -32
View File
@@ -3,6 +3,9 @@ mod ipc_auth;
#[cfg(all(windows, test))]
#[path = "ipc/config_tests.rs"]
pub(crate) mod config_tests;
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[path = "ipc/unix_credentials.rs"]
pub(crate) mod unix_credentials;
#[cfg(windows)]
#[path = "ipc/windows.rs"]
mod ipc_windows;
@@ -60,7 +63,9 @@ pub(crate) use ipc_auth::ensure_peer_executable_matches_current_by_pid_opt;
#[cfg(windows)]
pub(crate) use ipc_auth::log_rejected_windows_ipc_connection;
#[cfg(any(target_os = "linux", target_os = "macos"))]
use ipc_auth::{active_uid, authorize_service_scoped_ipc_connection};
use ipc_auth::{
active_uid, authorize_service_scoped_ipc_connection, authorize_unix_main_ipc_connection,
};
#[cfg(target_os = "macos")]
use ipc_auth::authorize_user_server_process;
#[cfg(windows)]
@@ -145,15 +150,13 @@ pub async fn connect_service(ms_timeout: u64) -> ResultType<ConnectionTmpl<ConnC
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(crate) async fn connect_trusted_device_service(
pub(crate) async fn connect_root_service(
ms_timeout: u64,
) -> ResultType<ConnectionTmpl<ConnClient>> {
let connection = connect_service(ms_timeout)
let connection = connect_with_path(ms_timeout, &Config::ipc_path(crate::POSTFIX_SERVICE))
.await
.map_err(crate::trusted_devices::authority::Unavailable)?;
if connection.peer_uid() != Some(0) {
bail!("Trusted-device system service is not an authenticated root peer");
}
ipc_auth::verify_service_uid(connection.peer_uid())?;
Ok(connection)
}
@@ -641,6 +644,10 @@ pub(crate) async fn start_with_listener(postfix: &str, mut incoming: Incoming) {
continue;
}
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
if postfix.is_empty() && !authorize_unix_main_ipc_connection(&stream) {
continue;
}
#[cfg(windows)]
if postfix.is_empty() {
// Windows main IPC (`postfix == ""`) is authorized here.
@@ -673,6 +680,10 @@ pub(crate) async fn start_with_listener(postfix: &str, mut incoming: Incoming) {
#[cfg(any(target_os = "linux", target_os = "macos"))]
if postfix == crate::POSTFIX_SERVICE {
if matches!(&data, Data::SyncConfig(_)) {
if let Err(err) = unix_credentials::verify_sync_client(&stream).await {
ipc_auth::log_rejected_sync_client(err);
break;
}
handle(data, &mut stream).await;
} else {
log::warn!(
@@ -1580,13 +1591,15 @@ pub async fn connect(ms_timeout: u64, postfix: &str) -> ResultType<ConnectionTmp
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
if postfix == crate::POSTFIX_SERVICE {
return connect_root_service(ms_timeout).await;
}
let use_user_main_ipc = USE_USER_MAIN_IPC.with(|use_user_main| use_user_main.get());
let is_root_main_ipc =
unsafe { hbb_common::libc::geteuid() == 0 } && postfix.is_empty() && use_user_main_ipc;
if is_root_main_ipc {
let uid = user_main_ipc_server_uid()?;
let path = Config::ipc_path_for_uid(uid, postfix);
return connect_with_path(ms_timeout, &path).await;
return unix_credentials::verified_main(ms_timeout, uid).await;
}
let path = Config::ipc_path(postfix);
return connect_with_path(ms_timeout, &path).await;
@@ -1725,6 +1738,46 @@ where
.await
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
async fn send_after_main_listener_ready(
&mut self,
data: &Data,
ms_timeout: u64,
) -> ResultType<()> {
// Keep the sender verifiable until admission. On macOS its peer PID disappears on close.
self.send(&Data::OnlineStatus(None)).await?;
let Some(Data::OnlineStatus(Some(_))) = self.next_timeout(ms_timeout).await? else {
bail!("Unexpected status response from main IPC listener");
};
self.send(data).await
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(crate) async fn send_takeover_close(&mut self, ms_timeout: u64) -> ResultType<()> {
self.send_after_main_listener_ready(&Data::Close, ms_timeout)
.await
}
#[cfg(any(
feature = "hwcodec",
all(test, any(target_os = "linux", target_os = "macos"))
))]
async fn send_hwcodec_config(
&mut self,
value: String,
readback_timeout_ms: Option<u64>,
) -> ResultType<()> {
self.send(&Data::HwCodecConfig(Some(value))).await?;
if let Some(ms) = readback_timeout_ms {
// The host must resolve this process's executable before it can consume the report.
self.send(&Data::HwCodecConfig(None)).await?;
let Some(Data::HwCodecConfig(Some(_))) = self.next_timeout(ms).await? else {
bail!("Host did not confirm the hardware codec configuration");
};
}
Ok(())
}
pub async fn next_timeout(&mut self, ms_timeout: u64) -> ResultType<Option<Data>> {
Ok(timeout(ms_timeout, self.next()).await??)
}
@@ -1786,9 +1839,7 @@ async fn get_config_async(name: &str, ms_timeout: u64) -> ResultType<Option<Stri
}
pub async fn set_config_async(name: &str, value: String) -> ResultType<()> {
let mut c = connect(1000, "").await?;
c.send_config(name, value).await?;
Ok(())
set_data_async(&Data::Config((name.to_owned(), Some(value)))).await
}
#[tokio::main(flavor = "current_thread")]
@@ -1797,9 +1848,13 @@ pub async fn set_data(data: &Data) -> ResultType<()> {
}
async fn set_data_async(data: &Data) -> ResultType<()> {
let mut c = connect(1000, "").await?;
c.send(data).await?;
Ok(())
const TIMEOUT_MS: u64 = 1_000;
let mut c = connect(TIMEOUT_MS, "").await?;
#[cfg(target_os = "macos")]
if unsafe { hbb_common::libc::geteuid() } != 0 && crate::platform::is_installed() {
return c.send_after_main_listener_ready(data, TIMEOUT_MS).await;
}
c.send(data).await
}
#[tokio::main(flavor = "current_thread")]
@@ -2176,11 +2231,7 @@ pub async fn set_socks(value: config::Socks5Server) -> ResultType<()> {
} else {
Some(value.clone())
});
connect(1_000, "")
.await?
.send(&Data::Socks(Some(value)))
.await?;
Ok(())
set_data_async(&Data::Socks(Some(value))).await
}
async fn get_socks_ws_(ms_timeout: u64) -> ResultType<(Option<config::Socks5Server>, String)> {
@@ -2211,16 +2262,12 @@ pub fn get_proxy_status() -> bool {
}
#[tokio::main(flavor = "current_thread")]
pub async fn test_rendezvous_server() -> ResultType<()> {
let mut c = connect(1000, "").await?;
c.send(&Data::TestRendezvousServer).await?;
Ok(())
set_data_async(&Data::TestRendezvousServer).await
}
#[tokio::main(flavor = "current_thread")]
pub async fn notify_deployed() -> ResultType<()> {
let mut c = connect(1000, "").await?;
c.send(&Data::Deployed).await?;
Ok(())
set_data_async(&Data::Deployed).await
}
#[tokio::main(flavor = "current_thread")]
@@ -2250,8 +2297,7 @@ pub async fn connect_to_user_session(usid: Option<u32>) -> ResultType<()> {
#[tokio::main(flavor = "current_thread")]
pub async fn notify_server_to_check_hwcodec() -> ResultType<()> {
connect(1_000, "").await?.send(&&Data::CheckHwcodec).await?;
Ok(())
set_data_async(&Data::CheckHwcodec).await
}
#[cfg(target_os = "windows")]
@@ -2316,12 +2362,17 @@ pub fn client_get_hwcodec_config_thread(wait_sec: u64) {
#[cfg(feature = "hwcodec")]
#[tokio::main(flavor = "current_thread")]
pub async fn hwcodec_process() {
const IPC_TIMEOUT_MS: u64 = 1_000;
#[cfg(any(target_os = "linux", target_os = "macos"))]
let readback_timeout_ms = crate::platform::is_installed().then_some(IPC_TIMEOUT_MS);
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let readback_timeout_ms = None;
let s = scrap::hwcodec::check_available_hwcodec();
for _ in 0..5 {
match crate::ipc::connect(1000, "").await {
match crate::ipc::connect(IPC_TIMEOUT_MS, "").await {
Ok(mut conn) => {
match conn
.send(&crate::ipc::Data::HwCodecConfig(Some(s.clone())))
.send_hwcodec_config(s.clone(), readback_timeout_ms)
.await
{
Ok(()) => {
@@ -2361,9 +2412,7 @@ pub async fn clear_wayland_screencast_restore_token(key: String) -> ResultType<b
))]
#[tokio::main(flavor = "current_thread")]
pub async fn update_controlling_session_count(count: usize) -> ResultType<()> {
let mut c = connect(1000, "").await?;
c.send(&Data::ControllingSessionCount(count)).await?;
Ok(())
set_data_async(&Data::ControllingSessionCount(count)).await
}
#[cfg(target_os = "linux")]
@@ -2471,6 +2520,78 @@ mod test {
#[cfg(any(target_os = "linux", target_os = "macos"))]
use super::*;
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[tokio::test]
async fn one_way_password_refresh_reports_listener_disconnect() {
const TIMEOUT_MS: u64 = 1_000;
let (gui, host) = tokio::net::UnixStream::pair().unwrap();
let mut host = ConnectionTmpl::new(host);
let gui = tokio::spawn(async move {
let refresh = Data::Config(("temporary-password".into(), Some(String::new())));
ConnectionTmpl::new(gui)
.send_after_main_listener_ready(&refresh, TIMEOUT_MS)
.await
});
assert!(matches!(
host.next_timeout(TIMEOUT_MS).await.unwrap(),
Some(Data::OnlineStatus(None))
));
assert_eq!(host.peer_pid(), Some(std::process::id()));
drop(host);
assert!(gui.await.unwrap().is_err(), "refresh reported success");
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[tokio::test]
async fn takeover_waits_for_listener_before_sending_close() {
const TIMEOUT_MS: u64 = 1_000;
let (sender, listener) = tokio::net::UnixStream::pair().unwrap();
let mut listener = ConnectionTmpl::new(listener);
let sender = tokio::spawn(async move {
ConnectionTmpl::new(sender)
.send_takeover_close(TIMEOUT_MS)
.await
});
assert!(matches!(
listener.next_timeout(TIMEOUT_MS).await.unwrap(),
Some(Data::OnlineStatus(None))
));
assert!(!sender.is_finished());
listener
.send(&Data::OnlineStatus(Some((0, false))))
.await
.unwrap();
assert!(matches!(
listener.next_timeout(TIMEOUT_MS).await.unwrap(),
Some(Data::Close)
));
sender.await.unwrap().unwrap();
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[tokio::test]
async fn codec_probe_waits_for_host_readback() {
const TIMEOUT_MS: u64 = 1_000;
let (probe, host) = tokio::net::UnixStream::pair().unwrap();
let mut host = ConnectionTmpl::new(host);
let probe = tokio::spawn(async move {
ConnectionTmpl::new(probe)
.send_hwcodec_config("{}".into(), Some(TIMEOUT_MS))
.await
});
assert!(matches!(host.next_timeout(TIMEOUT_MS).await.unwrap(),
Some(Data::HwCodecConfig(Some(value))) if value == "{}"));
assert!(matches!(
host.next_timeout(TIMEOUT_MS).await.unwrap(),
Some(Data::HwCodecConfig(None))
));
assert!(!probe.is_finished());
host.send(&Data::HwCodecConfig(Some("{}".into())))
.await
.unwrap();
probe.await.unwrap().unwrap();
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[test]
fn test_select_server_uid_uses_active_uid_when_no_server_found() {
+61
View File
@@ -170,6 +170,18 @@ pub(crate) fn is_allowed_service_peer_uid(peer_uid: u32, active_uid: Option<u32>
peer_uid == 0 || active_uid.is_some_and(|uid| uid == peer_uid)
}
#[cfg(any(target_os = "linux", target_os = "macos", test))]
#[inline]
fn is_allowed_unix_main_peer_uid(peer_uid: Option<u32>, server_uid: u32) -> bool {
peer_uid == Some(0) || peer_uid == Some(server_uid)
}
#[cfg(any(target_os = "linux", target_os = "macos", test))]
pub(super) fn verify_service_uid(peer_uid: Option<u32>) -> hbb_common::ResultType<()> {
hbb_common::anyhow::ensure!(peer_uid == Some(0), "Unix IPC service peer is not root");
Ok(())
}
#[cfg(target_os = "macos")]
#[inline]
fn console_owner_uid() -> Option<u32> {
@@ -519,6 +531,15 @@ pub(crate) fn ensure_peer_executable_matches_current_by_fd(
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
const UNAUTHORIZED_IPC_LOG_INTERVAL: std::time::Duration = std::time::Duration::from_secs(5);
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(super) fn log_rejected_sync_client(error: anyhow::Error) {
hbb_common::throttled_log!(
UNAUTHORIZED_IPC_LOG_INTERVAL,
warn,
"Rejected service sync client: {error}"
);
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[inline]
fn log_rejected_service_connection(postfix: &str, peer_uid: Option<u32>, active_uid: Option<u32>) {
@@ -572,6 +593,26 @@ pub(crate) fn log_rejected_windows_ipc_connection(
);
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(crate) fn authorize_unix_main_ipc_connection(stream: &Connection) -> bool {
let peer_uid = stream.peer_uid();
let server_uid = unsafe { libc::geteuid() };
if is_allowed_unix_main_peer_uid(peer_uid, server_uid)
&& (peer_uid == Some(0)
|| !crate::platform::is_installed()
|| ensure_peer_executable_matches_current_by_pid_opt(stream.peer_pid(), "").is_ok())
{
return true;
}
hbb_common::throttled_log!(
UNAUTHORIZED_IPC_LOG_INTERVAL,
warn,
"Rejected Unix main IPC connection: peer_uid={peer_uid:?}, server_uid={server_uid}, peer_pid={:?}",
stream.peer_pid()
);
false
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(crate) fn authorize_service_scoped_ipc_connection(stream: &Connection, postfix: &str) -> bool {
let peer_pid = stream.peer_pid();
@@ -871,6 +912,26 @@ impl ConnectionTmpl<parity_tokio_ipc::Connection> {
#[cfg(test)]
mod tests {
#[test]
fn service_client_requires_a_root_server() {
assert!(super::verify_service_uid(Some(0)).is_ok());
assert!(super::verify_service_uid(Some(1000)).is_err());
assert!(super::verify_service_uid(None).is_err());
}
#[test]
fn test_unix_main_peer_uid_policy() {
use super::is_allowed_unix_main_peer_uid;
assert!(is_allowed_unix_main_peer_uid(Some(0), 0));
assert!(!is_allowed_unix_main_peer_uid(Some(501), 0));
assert!(!is_allowed_unix_main_peer_uid(None, 0));
assert!(is_allowed_unix_main_peer_uid(Some(0), 501));
assert!(is_allowed_unix_main_peer_uid(Some(501), 501));
assert!(!is_allowed_unix_main_peer_uid(Some(502), 501));
assert!(!is_allowed_unix_main_peer_uid(None, 501));
}
#[test]
#[cfg(any(target_os = "macos", target_os = "linux"))]
fn test_service_peer_uid_policy() {
+138
View File
@@ -0,0 +1,138 @@
use super::{
connect_with_path, ipc_auth::ensure_peer_executable_matches_current_by_pid_opt, Connection,
};
use hbb_common::{
anyhow::{anyhow, ensure},
config::Config,
ResultType,
};
const IPC_TIMEOUT: u64 = 1_000;
pub(super) async fn verified_main(ms_timeout: u64, target: u32) -> ResultType<Connection> {
let connection = connect_with_path(ms_timeout, &Config::ipc_path_for_uid(target, "")).await?;
verify_main_peer(&connection, target)?;
Ok(connection)
}
fn verify_main_peer(connection: &Connection, target: u32) -> ResultType<()> {
ensure!(
connection.peer_uid() == Some(target),
"Unexpected main IPC server UID"
);
ensure_peer_executable_matches_current_by_pid_opt(connection.peer_pid(), "")
}
// Full service sync delegates credential changes to the actual user main server.
pub(super) async fn verify_sync_client(connection: &Connection) -> ResultType<()> {
let uid = connection
.peer_uid()
.ok_or_else(|| anyhow!("Missing sync client UID"))?;
if uid == 0 {
return Ok(());
}
let pid = connection
.peer_pid()
.ok_or_else(|| anyhow!("Missing sync client PID"))?;
let main = connect_with_path(IPC_TIMEOUT, &Config::ipc_path_for_uid(uid, "")).await?;
ensure!(
main.peer_uid() == Some(uid) && main.peer_pid() == Some(pid),
"Expected the user main IPC server"
);
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use hbb_common::tokio::{
self,
io::{AsyncReadExt, AsyncWriteExt},
net::UnixListener,
process::{Child, Command},
};
use std::{env, fs, os::unix::fs::DirBuilderExt, path::Path, process::Stdio};
const ROLE: &str = "RUSTDESK_TEST_SYNC_PEER";
const TEST_TIMEOUT_MS: u64 = 10_000;
// libtest also exits successfully when an exact filter selects no tests.
const OWNER_VERIFIED: i32 = 42;
#[tokio::test]
async fn service_sync_requires_main_listener_owner() -> ResultType<()> {
let mut child = Command::new(env::current_exe()?);
child
.arg("--exact")
.arg("ipc::unix_credentials::tests::service_sync_requires_main_listener_owner")
.kill_on_drop(true);
let Some(role) = env::var_os(ROLE) else {
let result =
hbb_common::timeout(TEST_TIMEOUT_MS, child.env(ROLE, "owner").output()).await??;
assert_eq!(
result.status.code(),
Some(OWNER_VERIFIED),
"{}",
String::from_utf8_lossy(&result.stdout)
);
return Ok(());
};
// Start both isolated peers before dropping privileges, even in a root-only build directory.
let other = if role == "owner" {
Some(child.env(ROLE, "sender").stdin(Stdio::piped()).spawn()?)
} else {
None
};
if unsafe { hbb_common::libc::geteuid() } == 0 {
const UNPRIVILEGED_UID: u32 = 65_534;
if unsafe { hbb_common::libc::setuid(UNPRIVILEGED_UID) } != 0 {
return Err(std::io::Error::last_os_error().into());
}
}
if let Some(other) = other {
check_sync_senders(other).await?;
std::process::exit(OWNER_VERIFIED);
}
let mut path = String::new();
tokio::io::stdin().read_to_string(&mut path).await?;
let mut socket = tokio::net::UnixStream::connect(path).await?;
// Keep the sender alive until the verifier closes its side.
assert_eq!(socket.read(&mut [0]).await?, 0);
Ok(())
}
async fn check_sync_senders(mut other: Child) -> ResultType<()> {
*hbb_common::config::APP_NAME.write().unwrap() =
format!("rd-sync-{}", uuid::Uuid::new_v4());
let main_path = Config::ipc_path("");
let directory = Path::new(&main_path).parent().unwrap().to_owned();
fs::DirBuilder::new().mode(0o700).create(&directory)?;
let sync_path = format!("{main_path}.sync");
let _cleanup = crate::SimpleCallOnReturn {
b: true,
f: Box::new(move || fs::remove_dir_all(&directory).unwrap()),
};
let _main = UnixListener::bind(main_path)?;
let mut sync = parity_tokio_ipc::Endpoint::new(sync_path.clone()).incoming()?;
let _owner = tokio::net::UnixStream::connect(&sync_path).await?;
let owner = Connection::new(sync.next().await.unwrap()?);
verify_sync_client(&owner).await?;
other
.stdin
.take()
.unwrap()
.write_all(sync_path.as_bytes())
.await?;
let sender = Connection::new(sync.next().await.unwrap()?);
assert_eq!(sender.peer_uid(), owner.peer_uid());
let result = verify_sync_client(&sender).await;
drop(sender);
assert!(other.wait().await?.success());
assert_eq!(
result.unwrap_err().to_string(),
"Expected the user main IPC server"
);
Ok(())
}
}
+2 -2
View File
@@ -1481,13 +1481,13 @@ impl DrmCaptureSwitch {
/// carries the whole config, and a long-lived process may hold an older copy of the rest.
#[cfg(feature = "drm")]
pub async fn sync_drm_capture_to_service(was_on: bool) {
use crate::ipc::{connect_trusted_device_service, Data};
use crate::ipc::{connect_root_service, Data};
use hbb_common::config::Config2;
if !is_root() || drm_capture_enabled() == was_on {
return;
}
let result = async {
let mut conn = connect_trusted_device_service(1000).await?;
let mut conn = connect_root_service(1000).await?;
let config2 = crate::trusted_devices::config::update(Config2::get_for_sync).await?;
let configs = Box::new((Config::get(), config2));
conn.send(&Data::SyncConfig(Some(configs))).await?;
+12 -3
View File
@@ -876,7 +876,7 @@ async fn sync_and_watch_config_dir(sync_done_tx: Option<tokio::sync::oneshot::Se
use hbb_common::sleep;
for i in 1..=tries {
sleep(i as f32 * CONFIG_SYNC_INTERVAL_SECS).await;
match crate::ipc::connect_trusted_device_service(1000).await {
match crate::ipc::connect_root_service(1000).await {
Ok(mut conn) => {
if !synced {
if conn.send(&Data::SyncConfig(None)).await.is_ok() {
@@ -947,7 +947,7 @@ async fn sync_and_watch_config_dir(sync_done_tx: Option<tokio::sync::oneshot::Se
match conn.send(&Data::SyncConfig(Some(cfg.clone().into()))).await {
Err(e) => {
log::error!("sync config to root failed: {}", e);
match crate::ipc::connect_trusted_device_service(1000).await {
match crate::ipc::connect_root_service(1000).await {
Ok(mut _conn) => {
conn = _conn;
log::info!("reconnected to ipc_service");
@@ -987,9 +987,18 @@ async fn sync_and_watch_config_dir(sync_done_tx: Option<tokio::sync::oneshot::Se
#[tokio::main(flavor = "current_thread")]
pub async fn stop_main_window_process() {
const IPC_TIMEOUT_MS: u64 = 1_000;
// this may also kill another --server process,
// but --server usually can be auto restarted by --service, so it is ok
if let Ok(mut conn) = crate::ipc::connect(1000, "").await {
if let Ok(mut conn) = crate::ipc::connect(IPC_TIMEOUT_MS, "").await {
#[cfg(any(target_os = "linux", target_os = "macos"))]
if unsafe { hbb_common::libc::geteuid() } != 0 && crate::platform::is_installed() {
allow_err!(
conn.send_takeover_close(IPC_TIMEOUT_MS).await,
"Main IPC takeover failed"
);
return;
}
conn.send(&crate::ipc::Data::Close).await.ok();
}
#[cfg(windows)]