From 174cfb384157f3bbad924963b6bd413ca9cbe8aa Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Fri, 28 Feb 2014 14:41:52 +0000 Subject: [PATCH] wait for hosts to terminate git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@37721 72102866-910b-0410-8b05-ffd578937521 --- EcControl.m | 107 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 28 deletions(-) diff --git a/EcControl.m b/EcControl.m index 05cea48..5c5853a 100644 --- a/EcControl.m +++ b/EcControl.m @@ -328,6 +328,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) NSMutableDictionary *fileBodies; NSMutableDictionary *fileDates; NSTimer *timer; + NSTimer *terminating; unsigned commandPingPosition; unsigned consolePingPosition; NSString *configFailed; @@ -1479,13 +1480,16 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) } } } - [a removeAllObjects]; } else { [self error: "non-Connection sent invalidation"]; } + if (nil != terminating && 0 == [commands count]) + { + [self cmdQuit: 0]; + } return self; } @@ -1746,6 +1750,36 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) return result; } +- (void) quitAll +{ + NSArray *hosts; + NSUInteger i; + + hosts = [[commands copy] autorelease]; + i = [hosts count]; + while (i-- > 0) + { + CommandInfo *c = [hosts objectAtIndex: i]; + + if ([commands indexOfObjectIdenticalTo: c] != NSNotFound) + { + NS_DURING + { + [[c obj] terminate]; + } + NS_HANDLER + { + NSLog(@"Caught: %@", localException); + } + NS_ENDHANDLER + } + } + if (0 == [commands count]) + { + [self cmdQuit: 0]; + } +} + - (NSData*) registerCommand: (id)c name: (NSString*)n { @@ -2172,35 +2206,44 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) } } +- (void) terminate: (NSTimer*)t +{ + if (nil == terminating) + { + [self information: @"Handling terminate." + type: LT_AUDIT + to: nil + from: nil]; + } + + if (nil == terminating) + { + terminating = [NSTimer scheduledTimerWithTimeInterval: 10.0 + target: self selector: @selector(terminate:) + userInfo: [NSDate new] + repeats: YES]; + } + + [self quitAll]; + + if (t != nil) + { + NSDate *when = (NSDate*)[t userInfo]; + + if ([when timeIntervalSinceNow] < -60.0) + { + [[self cmdLogFile: logname] + puts: @"Final shutdown.\n"]; + [terminating invalidate]; + terminating = nil; + [self cmdQuit: 0]; + } + } +} + - (void) terminate { - NSArray *hosts; - NSUInteger i; - - [self information: @"Received terminate message" - type: LT_AUDIT - to: nil - from: nil]; - hosts = [[commands copy] autorelease]; - i = [hosts count]; - while (i-- > 0) - { - CommandInfo *c = [hosts objectAtIndex: i]; - - if ([commands indexOfObjectIdenticalTo: c] != NSNotFound) - { - NS_DURING - { - [[c obj] terminate]; - } - NS_HANDLER - { - NSLog(@"Caught: %@", localException); - } - NS_ENDHANDLER - } - } - [self cmdQuit: 0]; + [self terminate: nil]; } - (void) timedOut: (NSTimer*)t @@ -2303,6 +2346,10 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) } [self reportAlarms]; inTimeout = NO; + if (nil != terminating && 0 == [commands count]) + { + [self cmdQuit: 0]; + } } - (id) recursiveInclude: (id)o @@ -2517,6 +2564,10 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) type: LT_AUDIT to: nil from: nil]; + if (nil != terminating && 0 == [commands count]) + { + [self cmdQuit: 0]; + } }