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).

This commit is contained in:
Richard Frith-Macdonald 2021-01-28 16:57:16 +00:00
parent 1ee2997360
commit 0fe10f12ed

View file

@ -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)
{