From bdee441b6ff97752d3fe61719baf74b3bc6e8f78 Mon Sep 17 00:00:00 2001 From: quantum-byte Date: Thu, 23 Mar 2023 10:55:57 +0100 Subject: [PATCH 1/2] Added fix for running idle trigger after system wake due to race condition --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 32f7ef3..ee97974 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1168,9 +1168,12 @@ fn main() { let mut watchdog = time::OffsetDateTime::now_utc().unix_timestamp(); loop { let idle = test_idle(&config, start); - // If it's idle, the idle command hasn't already run, and it has been + let now = time::OffsetDateTime::now_utc().unix_timestamp(); + // Look for clock jumps that indicate the system slept. In this case dont run idle + // trigger. + // Otherwise if it's idle, the idle command hasn't already run, and it has been // at least |idle_time| since the service started: enter idle state. - if idle.is_idle && !idle_triggered { + if watchdog + 30 < now && idle.is_idle && !idle_triggered { let tests = test_nonidle(&config); if !tests.is_blocked { println!("Idle state active:\n{}{}", idle, tests); From bff6f68c12348df685e19a9fa5bc62cb25d36f90 Mon Sep 17 00:00:00 2001 From: quantum-byte Date: Fri, 24 Mar 2023 13:36:05 +0100 Subject: [PATCH 2/2] Fix clock jump condition --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ee97974..7b16144 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1173,7 +1173,7 @@ fn main() { // trigger. // Otherwise if it's idle, the idle command hasn't already run, and it has been // at least |idle_time| since the service started: enter idle state. - if watchdog + 30 < now && idle.is_idle && !idle_triggered { + if watchdog + 30 > now && idle.is_idle && !idle_triggered { let tests = test_nonidle(&config); if !tests.is_blocked { println!("Idle state active:\n{}{}", idle, tests);