more shutdown tweaks (better control over time allowed)

This commit is contained in:
Richard Frith-Macdonald 2019-07-15 10:10:05 +01:00
parent 76077a56a4
commit 8cd2ff9fab
3 changed files with 36 additions and 2 deletions

View file

@ -8,6 +8,8 @@
crash) is greater than any utility in having quit force an abort (the
OS 'kill' command is adequate for that) of any process still capable
of responding to the request over Distributed Objects.
Added method to see how long we have been quitting, and method to
set how long we are allowed to quit.
2019-07-12 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -637,11 +637,17 @@ extern NSString* cmdVersion(NSString *ver);
/** Returns YES if the process is attempting a graceful shutdown,
* NO otherwise. This also checks to see if the process has been
* attempting to shut down for too long, and if it has been going
* on for over three minutes, aborts the process.<br />
* on for over three minutes (or the value set by -ecQuitLimit:),
* aborts the process.<br />
* Subclasses must not override this method.
*/
- (BOOL) ecIsQuitting;
/** Returns the interval since the process started quitting, or zero
* if it is not quitting (as determined by calling -ecIsQuitting).
*/
- (NSTimeInterval) ecQuitDuration;
/** This method is designed for handling an orderly shutdown by calling
* -ecWillQuit: with the supplied reason, then -ecHandleQuit, and finally
* calling -ecDidQuit: passing the supplied status.<br />
@ -652,6 +658,13 @@ extern NSString* cmdVersion(NSString *ver);
*/
- (oneway void) ecQuitFor: (NSString*)reason with: (NSInteger)status;
/** Sets the number of seconds the graceful shutdown process is permitted
* to take before the process will attempt to abort on the next check to
* see if it quitting (-ecIsQuitting). The default is 180.0 seconds.<br />
* This method returns the previous value of the setting.
*/
- (NSTimeInterval) ecQuitLimit: (NSTimeInterval)seconds;
/** Returns the quit reason supplied to the -ecQuitFor:with method.
*/
- (NSString*) ecQuitReason;

View file

@ -268,6 +268,7 @@ static NSTimeInterval initAt = 0.0;
*/
static NSTimeInterval beganQuitting = 0.0; // Start of orderly shutdown
static BOOL ecQuitHandled = NO; // Has ecHandleQuit run?
static NSTimeInterval ecQuitLimit = 180.0; // Time allowed for quit
static NSInteger ecQuitStatus = -1; // Status for the quit
static NSString *ecQuitReason = nil; // Reason for the quit
@ -282,7 +283,7 @@ ecIsQuitting()
return NO;
}
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
if (now - beganQuitting >= 180.0)
if (now - beganQuitting >= ecQuitLimit)
{
NSLog(@"abort: quitting took too long (after %g sec)\n",
(now - beganQuitting));
@ -2642,6 +2643,15 @@ static BOOL ecDidAwaken = NO;
return ecIsQuitting();
}
- (NSTimeInterval) ecQuitDuration
{
if (ecIsQuitting())
{
return [NSDate timeIntervalSinceReferenceDate] - beganQuitting;
}
return 0.0;
}
- (oneway void) ecQuitFor: (NSString*)reason with: (NSInteger)status
{
[ecLock lock];
@ -2668,6 +2678,15 @@ static BOOL ecDidAwaken = NO;
}
}
- (NSTimeInterval) ecQuitLimit: (NSTimeInterval)seconds
{
NSTimeInterval old = ecQuitLimit;
ecQuitLimit = seconds;
return old;
}
- (NSString*) ecQuitReason
{
return ecQuitReason;