From 4b74af2de937b946c32cbd7a302dfd460faa65fe Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 19 Jun 2008 22:16:19 -0700 Subject: [PATCH] Fixes 240385 The relaunch tool sadly now polls for the host app being closed, rather than registering for notifications. But there was some race condition which had problems with the latter. --- relaunch.m | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/relaunch.m b/relaunch.m index be65c539..060c45ce 100644 --- a/relaunch.m +++ b/relaunch.m @@ -16,30 +16,22 @@ - (id) initWithExecutablePath:(const char *)execPath parentProcessId:(pid_t)ppid { self = [super init]; - if (self != nil) { + if (self != nil) + { executablePath = execPath; parentProcessId = ppid; - - [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationDidTerminate:) name:NSWorkspaceDidTerminateApplicationNotification object:nil]; - if (getppid() == 1) { - // ppid is launchd (1) => parent terminated already + if (getppid() == 1) // ppid is launchd (1) => parent terminated already [self relaunch]; - } - - ProcessSerialNumber psn; - if (GetProcessForPID(ppid, &psn) == procNotFound) { - [self relaunch]; - } + [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(watchdog:) userInfo:nil repeats:YES]; } return self; } -- (void) applicationDidTerminate:(NSNotification *)notification +- (void)watchdog:(NSTimer *)timer { - if (parentProcessId == [[[notification userInfo] valueForKey:@"NSApplicationProcessIdentifier"] intValue]) { - // parent just terminated + ProcessSerialNumber psn; + if (GetProcessForPID(parentProcessId, &psn) == procNotFound) [self relaunch]; - } } - (void) relaunch