fix for bnug #38981

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36621 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-05-15 10:44:16 +00:00
parent e146ff2eb9
commit f4ac6d12c5
2 changed files with 32 additions and 21 deletions

View file

@ -1,3 +1,7 @@
2013-05-15 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSMessagePortNameServer.m: fix for bug #38981
2013-05-13 Fred Kiefer <FredKiefer@gmx.de> 2013-05-13 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Foundation/NSKeyedArchiver.h, * Headers/Foundation/NSKeyedArchiver.h,

View file

@ -131,7 +131,7 @@ static void clean_up_names(void)
NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSFileManager *mgr; NSFileManager *mgr;
NSString *path; NSString *path;
NSString *pref; NSString *pid;
NSString *file; NSString *file;
NSEnumerator *files; NSEnumerator *files;
@ -149,34 +149,41 @@ static void clean_up_names(void)
path = NSTemporaryDirectory(); path = NSTemporaryDirectory();
path = [path stringByAppendingPathComponent: @"NSMessagePort"]; path = [path stringByAppendingPathComponent: @"NSMessagePort"];
path = [path stringByAppendingPathComponent: @"names"]; path = [path stringByAppendingPathComponent: @"names"];
pref = [NSString stringWithFormat: @"%i.", pid = [NSString stringWithFormat: @"%i",
[[NSProcessInfo processInfo] processIdentifier]]; [[NSProcessInfo processInfo] processIdentifier]];
mgr = [NSFileManager defaultManager]; mgr = [NSFileManager defaultManager];
files = [[mgr directoryContentsAtPath: path] objectEnumerator]; files = [[mgr directoryContentsAtPath: path] objectEnumerator];
while ((file = [files nextObject]) != nil) while ((file = [files nextObject]) != nil)
{ {
NSString *old = [path stringByAppendingPathComponent: file]; NSString *old = [path stringByAppendingPathComponent: file];
NSString *port = [NSString stringWithContentsOfFile: old]; NSArray *lines;
if (YES == [port hasPrefix: pref]) lines = [[NSString stringWithContentsOfFile: old]
{ componentsSeparatedByString: @"\n"];
NSDebugMLLog(@"NSMessagePort", @"Removing old name %@", old); if ([lines count] == 2)
[mgr removeFileAtPath: old handler: nil]; {
} NSString *opid = [lines objectAtIndex: 1];
else
{
int pid = [port intValue];
if (pid > 0) if (YES == [opid isEqual: pid])
{ {
if (NO == [NSProcessInfo _exists: pid]) NSDebugMLLog(@"NSMessagePort", @"Removing old name %@", old);
{ [mgr removeFileAtPath: old handler: nil];
NSDebugMLLog(@"NSMessagePort", }
@"Removing old name %@ for process %d", old, pid); else if ([opid intValue] > 0)
[mgr removeFileAtPath: old handler: nil]; {
} if (NO == [NSProcessInfo _exists: [opid intValue]])
} {
} NSDebugMLLog(@"NSMessagePort",
@"Removing old name %@ for process %@", old, pid);
[mgr removeFileAtPath: old handler: nil];
}
}
}
else
{
NSDebugMLLog(@"NSMessagePort", @"Removing bad name %@", old);
[mgr removeFileAtPath: old handler: nil];
}
} }
[pool release]; [pool release];
} }