diff --git a/proxy_agent_extension/src/common.rs b/proxy_agent_extension/src/common.rs index 4d5ce712..0d8d04e9 100644 --- a/proxy_agent_extension/src/common.rs +++ b/proxy_agent_extension/src/common.rs @@ -8,6 +8,7 @@ use crate::structs; use crate::structs::FormattedMessage; use crate::structs::HandlerEnvironment; use crate::structs::TopLevelStatus; +#[cfg(windows)] use proxy_agent_shared::service; use proxy_agent_shared::{misc_helpers, telemetry}; use std::fs; @@ -167,7 +168,28 @@ pub fn get_current_seq_no(exe_path: &Path) -> String { } pub fn get_proxy_agent_service_path() -> PathBuf { - service::query_service_executable_path(constants::PROXY_AGENT_SERVICE_NAME) + #[cfg(windows)] + { + match service::query_service_executable_path(constants::PROXY_AGENT_SERVICE_NAME) { + Ok(path) => path, + Err(e) => { + logger::write(format!( + "get_proxy_agent_service_path: query failed with error: {e}" + )); + PathBuf::new() + } + } + } + // On Linux the GPA binary is always installed at a well-known fixed path by the + // setup tool. Avoid querying `systemctl show --property=ExecStart` here: the + // systemd unit-file cache may not be hot right after install, causing + // ExecStart to come back empty, which previously triggered a false + // VersionMismatch and a spurious re-install on every enable invocation. + #[cfg(not(windows))] + { + PathBuf::from(proxy_agent_shared::linux::EXE_FOLDER_PATH) + .join(constants::PROXY_AGENT_SERVICE_NAME) + } } pub fn get_proxy_agent_exe_path() -> PathBuf { diff --git a/proxy_agent_setup/src/running.rs b/proxy_agent_setup/src/running.rs index f6048e88..ca0809d1 100644 --- a/proxy_agent_setup/src/running.rs +++ b/proxy_agent_setup/src/running.rs @@ -11,9 +11,17 @@ pub fn proxy_agent_running_folder(_service_name: &str) -> PathBuf { let path; #[cfg(windows)] { - path = match service::query_service_executable_path(_service_name).parent() { - Some(p) => p.to_path_buf(), - None => proxy_agent_parent_folder().join("Package"), + path = match service::query_service_executable_path(_service_name) { + Ok(exe_path) => match exe_path.parent() { + Some(p) => p.to_path_buf(), + None => proxy_agent_parent_folder().join("Package"), + }, + Err(e) => { + logger::write(format!( + "query_service_executable_path failed for {_service_name}: {e}" + )); + proxy_agent_parent_folder().join("Package") + } }; } #[cfg(not(windows))] diff --git a/proxy_agent_shared/src/service.rs b/proxy_agent_shared/src/service.rs index 2bda4385..a3a0815c 100644 --- a/proxy_agent_shared/src/service.rs +++ b/proxy_agent_shared/src/service.rs @@ -94,30 +94,23 @@ pub fn update_service( } } -pub fn query_service_executable_path(service_name: &str) -> PathBuf { +pub fn query_service_executable_path(service_name: &str) -> Result { #[cfg(windows)] { match windows_service::query_service_config(service_name) { Ok(service_config) => { logger_manager::write_info(format!("Service {service_name} successfully queried",)); - service_config.executable_path.to_path_buf() + Ok(service_config.executable_path.to_path_buf()) } Err(e) => { logger_manager::write_info(format!("Service {service_name} query failed: {e}",)); - eprintln!("Service {service_name} query failed: {e}"); - PathBuf::new() + Err(e) } } } #[cfg(not(windows))] { - match linux_service::query_service_executable_path(service_name) { - Ok(path) => path, - Err(e) => { - eprintln!("Service {service_name} query failed: {e}"); - PathBuf::new() - } - } + linux_service::query_service_executable_path(service_name) } }