More changes to make startup configuration easier to handle in a robust manner

This commit is contained in:
Richard Frith-Macdonald 2017-06-23 15:18:21 +01:00
parent 00ab926033
commit 974811f604
3 changed files with 58 additions and 42 deletions

View file

@ -9,7 +9,9 @@
date. Fixes the bug where files were archived to a folder with the
wrong date on startup, and simplifies archiving code generally.
Move startup of timeouts to -ecRun so that they won't occur until
after all initialisation.
after all initialisation. Add -ecAwaken, -ecDidAwaken, and
-ecConfigurationError: to make it easy to initialise stuff at the
start of -ecRun and to ignore config updates before that happens.
2017-03-06 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -779,11 +779,8 @@ extern NSString* cmdVersion(NSString *ver);
* method will find the configuration unchanged since the previous
* time that it was called.<br />
* The return value of this method is used to control automatic generation
* of alarms for fatal configuration errors. If the return value is nil
* (the default), then any configuration error alarm is cleared.<br />
* Otherwise, a configuration error alarm will be raised (using the
* returned string as the 'additional text' of the alarm), and the process
* will be terminated by a call to -cmdQuit: with an argument of 1.<br />
* of alarms for fatal configuration errors by passing it to the
* -ecConfigurationError: method.<br />
* When you implement this method, you must ensure that your implementation
* calls the superclass implementation, and if that returns a non-nil
* result, you should pass that on as the return value from your own
@ -1003,10 +1000,22 @@ extern NSString* cmdVersion(NSString *ver);
* If you are not using -ecRun you should call this method explicitly in your
* own code.<br />
* The default implementation does nothing but record the fact that it has
* been called (for -ecDidAwaken).
* been called (for -ecDidAwaken).<br />
*/
- (void) ecAwaken;
/** Called to handle fatal configuration problems (or with a nil argument,
* to clear any outstanding alarm about a configuration problem).<br />
* If err is not nil, a configuration error alarm will be raised (using the
* err string as the 'additional text' of the alarm), and the process
* will be terminated by a call to -cmdQuit: with an argument of 1.<br />
* If you override this method, you should ensure that your implementation
* calls the superclass implementation.<br />
* This method is called automatically with the result of -cmdUpdated when
* process configuration changes.
*/
- (void) ecConfigurationError: (NSString*)err;
/** Returns YES if the base implementation of -ecAwaken has been called,
* NO otherwise. You may use this in conjunction with -ecDoLock and
* -ecUnLock to ensure that you have thread-safe initialisation of your

View file

@ -1653,6 +1653,45 @@ static BOOL ecDidAwaken = NO;
ecDidAwaken = YES;
}
- (void) ecConfigurationError: (NSString*)err
{
if ([err length] > 0)
{
EcAlarm *a;
/* Truncate additional text to fit if necessary.
*/
err = [err stringByTrimmingSpaces];
if ([err length] > 255)
{
err = [err substringToIndex: 255];
while (255 < strlen([err UTF8String]))
{
err = [err substringToIndex: [err length] - 1];
}
}
a = [EcAlarm alarmForManagedObject: nil
at: nil
withEventType: EcAlarmEventTypeProcessingError
probableCause: EcAlarmConfigurationOrCustomizationError
specificProblem: @"Fatal configuration error"
perceivedSeverity: EcAlarmSeverityMajor
proposedRepairAction:
_(@"Correct config (check additional text and/or log for details).")
additionalText: err];
[self alarm: a];
[alarmDestination shutdown];
cmdIsQuitting = YES;
[self cmdQuit: 1];
}
else
{
[self clearConfigurationFor: nil
specificProblem: @"Fatal configuration error"
additionalText: @"Configuration updated"];
}
}
- (BOOL) ecDidAwaken
{
return ecDidAwaken;
@ -5125,41 +5164,7 @@ With two parameters ('maximum' and a number),\n\
err = @"the -cmdUpdated method raised an exception";
NS_ENDHANDLER
}
if ([err length] > 0)
{
EcAlarm *a;
/* Truncate additional text to fit if necessary.
*/
err = [err stringByTrimmingSpaces];
if ([err length] > 255)
{
err = [err substringToIndex: 255];
while (255 < strlen([err UTF8String]))
{
err = [err substringToIndex: [err length] - 1];
}
}
a = [EcAlarm alarmForManagedObject: nil
at: nil
withEventType: EcAlarmEventTypeProcessingError
probableCause: EcAlarmConfigurationOrCustomizationError
specificProblem: @"Fatal configuration error"
perceivedSeverity: EcAlarmSeverityMajor
proposedRepairAction:
_(@"Correct config (check additional text and/or log for details).")
additionalText: err];
[self alarm: a];
[alarmDestination shutdown];
cmdIsQuitting = YES;
[self cmdQuit: 1];
}
else
{
[self clearConfigurationFor: nil
specificProblem: @"Fatal configuration error"
additionalText: @"Configuration updated"];
}
[self ecConfigurationError: err];
}
}