From 26dc46d917a17561cfadd8e3320ff033561aa68c Mon Sep 17 00:00:00 2001 From: Cherry <13651622+MolotovCherry@users.noreply.github.com> Date: Mon, 2 Sep 2024 06:46:06 -0700 Subject: [PATCH] Separate logon/logoff into separate arms --- pueue/src/daemon/service.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/pueue/src/daemon/service.rs b/pueue/src/daemon/service.rs index 3414b35..97c7663 100644 --- a/pueue/src/daemon/service.rs +++ b/pueue/src/daemon/service.rs @@ -41,7 +41,7 @@ use windows_service::{ service::{ ServiceAccess, ServiceControl, ServiceControlAccept, ServiceErrorControl, ServiceExitCode, ServiceInfo, ServiceStartType, ServiceState, ServiceStatus, ServiceType, - SessionChangeReason, + SessionChangeParam, SessionChangeReason, SessionNotification, }, service_control_handler::{self, ServiceControlHandlerResult}, service_dispatcher, @@ -150,26 +150,30 @@ fn run_service() -> Result<()> { ServiceControlHandlerResult::NoError } - ServiceControl::SessionChange(param) => { - match param.reason { - SessionChangeReason::SessionLogon => { - if !spawner.running() { - if let Err(e) = spawner.start(Some(param.notification.session_id)) { - error!("failed to spawn: {e}"); - } - } + // Logon + ServiceControl::SessionChange(SessionChangeParam { + reason: SessionChangeReason::SessionLogon, + notification: SessionNotification { session_id, .. }, + }) => { + if !spawner.running() { + if let Err(e) = spawner.start(Some(session_id)) { + error!("failed to spawn: {e}"); } - - SessionChangeReason::SessionLogoff => { - spawner.stop(); - } - - _ => (), } ServiceControlHandlerResult::NoError } + // Logoff + ServiceControl::SessionChange(SessionChangeParam { + reason: SessionChangeReason::SessionLogoff, + .. + }) => { + spawner.stop(); + + ServiceControlHandlerResult::NoError + } + // All services must accept Interrogate even if it's a no-op. ServiceControl::Interrogate => ServiceControlHandlerResult::NoError, @@ -412,7 +416,7 @@ impl Spawner { let mut handle = self.child.lock().unwrap().0 .0; if handle.is_invalid() { - while !self.running.load(Ordering::Relaxed) { + while !self.running() { thread::park(); }