From cbcf93e905046b7dd98dab49e119ec4254c28192 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 6 Mar 2007 18:38:22 +0000 Subject: [PATCH] Add auto shutdown for gdnc and filesystem fixup for spelling dictionaries git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@24787 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++++++++ Source/NSDistributedNotificationCenter.m | 18 +++++++++++++++--- Source/NSSpellServer.m | 7 +++++-- Tools/gdnc.m | 13 +++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66735158d..822c2e23d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-03-06 Richard Frith-Macdonald + + * Source/NSSpellServer.m: Use Library directory in user domain for + local dictionaries. + * Source/NSDistributedNotificationCenter.m: autolaunch gdnc with the + --auto option. + * Tools/gdnc.m: Understand --auto to mean that we should shut down + automatically when all connections in to us are dropped. + 2007-03-06 Nicola Pero * configure.ac: Added GNUSTEP_SYSTEM_USERS_DIR, diff --git a/Source/NSDistributedNotificationCenter.m b/Source/NSDistributedNotificationCenter.m index 1897e6662..5847c0dbd 100644 --- a/Source/NSDistributedNotificationCenter.m +++ b/Source/NSDistributedNotificationCenter.m @@ -710,17 +710,29 @@ static NSDistributedNotificationCenter *netCenter = nil; if (_type == GSNetworkNotificationCenterType) { args = [NSArray arrayWithObjects: - @"-GSNetwork", @"YES", nil]; + @"-GSNetwork", @"YES", + @"--auto", + nil]; } else if (_type == GSPublicNotificationCenterType) { args = [NSArray arrayWithObjects: - @"-GSPublic", @"YES", nil]; + @"-GSPublic", @"YES", + @"--auto", + nil]; } else if ([host length] > 0) { args = [NSArray arrayWithObjects: - @"-NSHost", host, nil]; + @"-NSHost", host, + @"--auto", + nil]; + } + else + { + args = [NSArray arrayWithObjects: + @"--auto", + nil]; } [NSTask launchedTaskWithLaunchPath: cmd arguments: args]; diff --git a/Source/NSSpellServer.m b/Source/NSSpellServer.m index eea398c8a..1ffd258f6 100644 --- a/Source/NSSpellServer.m +++ b/Source/NSSpellServer.m @@ -173,7 +173,7 @@ GSSpellServerName(NSString *vendor, NSString *language) NSString *path = nil; NSString *user_gsroot = nil; - user_gsroot = [NSSearchPathForDirectoriesInDomains(NSUserDirectory, + user_gsroot = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]; if (currentLanguage != nil) @@ -182,7 +182,8 @@ GSSpellServerName(NSString *vendor, NSString *language) NSFileManager *mgr = [NSFileManager defaultManager]; // Build the path and try to get the dictionary - dirPath = [user_gsroot stringByAppendingPathComponent: GNU_UserDictionariesDir]; + dirPath = [user_gsroot stringByAppendingPathComponent: + GNU_UserDictionariesDir]; path = [dirPath stringByAppendingPathComponent: currentLanguage]; if (![mgr fileExistsAtPath: path ]) @@ -236,6 +237,7 @@ GSSpellServerName(NSString *vendor, NSString *language) if ((path = [self _pathToDictionary: language]) != nil) { NSArray *wordarray = [NSArray arrayWithContentsOfFile: path]; + if (wordarray == nil) { NSLog(@"Unable to load user dictionary from path %@",path); @@ -351,6 +353,7 @@ is a set of words learned by the spell service for that particular user. if ((path = [self _pathToDictionary: language]) != nil) { NSMutableSet *set = [_userDictionaries objectForKey: language]; + if (![[set allObjects] writeToFile: path atomically: YES]) { NSLog(@"Unable to save dictionary to path %@",path); diff --git a/Tools/gdnc.m b/Tools/gdnc.m index 9e78c915a..4da9e6f08 100644 --- a/Tools/gdnc.m +++ b/Tools/gdnc.m @@ -40,6 +40,7 @@ #endif static BOOL is_daemon = NO; /* Currently running as daemon. */ +static BOOL auto_stop = NO; /* Should we shut down when unused? */ static char ebuf[2048]; #ifdef HAVE_SYSLOG @@ -642,6 +643,14 @@ ihandler(int sig) [self removeObserversForClients: table]; NSFreeMapTable(table); } + + if (auto_stop == YES && NSCountMapTable(connections) == 0) + { + /* If there is nothing else using this process, and this is not + * a daemon, then we can quietly terminate. + */ + exit(EXIT_SUCCESS); + } } return nil; } @@ -1047,6 +1056,10 @@ main(int argc, char** argv, char** env) printf("--verbose\tMore verbose debug output\n"); exit(EXIT_SUCCESS); } + if ([[pInfo arguments] containsObject: @"--auto"] == YES) + { + auto_stop = YES; + } if ([[pInfo arguments] containsObject: @"--daemon"] == YES) { subtask = NO;