From 0fe10f12edfdba3c9896a328715a3caf1feb4bc1 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Thu, 28 Jan 2021 16:57:16 +0000 Subject: [PATCH] Calculate abortDate in one place. Make sure it takes the global terminate date (if any) into account. Fix bug clearing the global termination date (should never happen since, when that date is reached, the Command server should exit). --- EcCommand.m | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/EcCommand.m b/EcCommand.m index fd34e60..ab5dc16 100644 --- a/EcCommand.m +++ b/EcCommand.m @@ -107,6 +107,23 @@ static NSTimeInterval quitTime = 120.0; */ static NSDate *terminateBy = nil; +static NSTimeInterval +abortDateFromStoppingDate(NSTimeInterval stopping) +{ + NSTimeInterval abortDate = stopping + quitTime; + + if (terminateBy) + { + NSTimeInterval ti = [terminateBy timeIntervalSinceReferenceDate]; + + if (ti < abortDate) + { + abortDate = ti; + } + } + return abortDate; +} + static NSUInteger launchLimit = 0; static BOOL launchEnabled = NO; static NSMutableDictionary *launchInfo = nil; @@ -2315,7 +2332,7 @@ valgrindLog(NSString *name) { [self resetDelay]; stoppingDate = [NSDate timeIntervalSinceReferenceDate]; - abortDate = stoppingDate + quitTime; + abortDate = abortDateFromStoppingDate(stoppingDate); if (nil == client) { /* No connection to client established ... try to shut it down @@ -2401,7 +2418,6 @@ valgrindLog(NSString *name) awakenedDate = 0.0; stableDate = 0.0; abortDate = 0.0; - DESTROY(terminateBy); // Termination completed if (clientLostDate > 0.0 || clientQuitDate > 0.0) { @@ -2622,15 +2638,7 @@ valgrindLog(NSString *name) } if (abortDate <= 0.0) { - abortDate = stoppingDate + quitTime; - } - if (nil != terminateBy) - { - ti = [terminateBy timeIntervalSinceReferenceDate]; - if (ti < abortDate) - { - abortDate = ti; - } + abortDate = abortDateFromStoppingDate(stoppingDate); } if (abortDate <= now) {