[39658] branches/gsoc08-framework/MacPorts_Framework_Release
Revision: 39658 http://trac.macosforge.org/projects/macports/changeset/39658 Author: armahg@macports.org Date: 2008-08-28 02:25:00 -0700 (Thu, 28 Aug 2008) Log Message: ----------- Added ConnectionOpen2() function to help debug Broken Pipe errors for Framework<->HelperTool IPC. Modified Paths: -------------- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.h branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.m branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.h Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m =================================================================== --- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m 2008-08-28 07:55:13 UTC (rev 39657) +++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m 2008-08-28 09:25:00 UTC (rev 39658) @@ -180,6 +180,78 @@ return err; } +static int ConnectionOpen2(ConnectionRef *connPtr, const char * sockPath) +// Opens a connection to the server. +// +// On entry, connPtr must not be NULL +// On entry, *connPtr must be NULL +// Returns an errno-style error code +// On success, *connPtr will not be NULL +// On error, *connPtr will be NULL +{ + int err; + ConnectionRef conn; + Boolean sayGoodbye; + + assert( connPtr != NULL); + assert(*connPtr == NULL); + + sayGoodbye = false; + + // Allocate a ConnectionState structure and fill out some basic fields. + + err = 0; + conn = (ConnectionRef) calloc(1, sizeof(*conn)); + if (conn == NULL) { + err = ENOMEM; + } + if (err == 0) { + conn->fMagic = kConnectionStateMagic; + + // For clean up to work properly, we must make sure that, if + // the connection record is allocated successfully, we always + // set fSockFD to -1. So, while the following line is redundant + // in the current code, it's present to press home this point. + + conn->fSockFD = -1; + } + + // Create a UNIX domain socket and connect to the server. + + if (err == 0) { + conn->fSockFD = socket(AF_UNIX, SOCK_STREAM, 0); + err = MoreUNIXErrno(conn->fSockFD); + } + if (err == 0) { + struct sockaddr_un connReq; + + connReq.sun_len = sizeof(connReq); + connReq.sun_family = AF_UNIX; + //strcpy(connReq.sun_path, kServerSocketPath); + strcpy(connReq.sun_path, sockPath); + + err = connect(conn->fSockFD, (struct sockaddr *) &connReq, SUN_LEN(&connReq)); + err = MoreUNIXErrno(err); + + sayGoodbye = (err == 0); + } + + // Clean up. + + if (err != 0) { + ConnectionCloseInternal(conn, sayGoodbye); + conn = NULL; + } + *connPtr = conn; + + assert( (err == 0) == (*connPtr != NULL) ); + + return err; +} + + + + static int ConnectionOpen(ConnectionRef *connPtr) // Opens a connection to the server. // @@ -600,7 +672,7 @@ // Connect to the server. if (err == 0) { - err = ConnectionOpen(&iConn); + //err = ConnectionOpen(&iConn); //asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"MPHelperTool: Installed Signal to Socket!"); [ASLLogger logString:@"MPHelperTool: Installed Signal to Socket!"]; } @@ -752,7 +824,11 @@ NSString * data = [NSString stringWithUTF8String:log]; [ASLLogger logString:data]; if (notifier != nil && [notifier connected]) { - [notifier doShout:data]; + if([notifier doShout:data]) + [ASLLogger logString:@"DoShout successful"]; + else + [ASLLogger logString:@"DoShout unsuccessful"]; + } else [ASLLogger logString:[NSString stringWithFormat:@"notifier has value %@", notifier]]; Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m =================================================================== --- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m 2008-08-28 07:55:13 UTC (rev 39657) +++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m 2008-08-28 09:25:00 UTC (rev 39658) @@ -397,15 +397,12 @@ [NSThread detachNewThreadSelector:@selector(startIPCServerThread) toTarget:notificationObject withObject:nil]; + //[notificationObject startIPCServerThread]; //} secondResult = [self evaluateStringWithMPHelperTool:statement error:mportError]; - //We can stop the thread now - //if ([notificationObject respondsToSelector:@selector(stopServerThread)]) { - NSLog(@"STOPPING SERVER THREAD"); - [notificationObject stopIPCServerThread]; - //} + return secondResult; } Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.h =================================================================== --- branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.h 2008-08-28 07:55:13 UTC (rev 39657) +++ branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.h 2008-08-28 09:25:00 UTC (rev 39658) @@ -8,9 +8,12 @@ #import "MPNotifications.h" +static int clientHasQuit = 0; +static int hasInstalledSignalsToSocket = 0; @interface MPNotifications (IPCAdditions) - +-(BOOL) terminateBackgroundThread; +-(void) setTerminateBackgroundThread:(BOOL)newStatus; -(void) startIPCServerThread; -(void) prepareIPCServerThread; -(void) stopIPCServerThread; Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.m =================================================================== --- branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.m 2008-08-28 07:55:13 UTC (rev 39657) +++ branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications+IPCAdditions.m 2008-08-28 09:25:00 UTC (rev 39658) @@ -884,6 +884,7 @@ return result; } + static Boolean ClientQuit(ClientState *client, PacketQuit *packet) // A packet handler for the Quit packet. See the large comment above for // a discussion of the general form of a packet handler. @@ -905,11 +906,17 @@ // the client's fault (-: result = ClientSendReply(client, &packet->fHeader, 0); - - NSLog(@"CLIENT QUIT BEING CALLED (YAAAY!!)"); } - return result; + if (result) { + //This is a shared variable, the server thread uses this to keep the while + //loop running. For now i'm not synchronizing variable access since the + //worst that could happen is that the server is late in reading a chaged + //value update + clientHasQuit = 1; + } + + return result; } static void ClientGotData(ClientState *client, const void *data) @@ -1329,7 +1336,14 @@ @implementation MPNotifications (IPCAdditions) +-(BOOL) terminateBackgroundThread { + return terminateBackgroundThread; +} +-(void) setTerminateBackgroundThread:(BOOL)newStatus { + terminateBackgroundThread = newStatus; +} + -(void) startIPCServerThread { NSAutoreleasePool * sPool = [[NSAutoreleasePool alloc] init]; @@ -1361,6 +1375,7 @@ // SIGINT and SIGINFO to our runloop. If either of these signals occurs, we // end up executing SignalRunLoopCallback. if (err == 0) { + if (hasInstalledSignalsToSocket == 0) { sigset_t interestingSignals; (void) sigemptyset(&interestingSignals); (void) sigaddset(&interestingSignals, SIGINT); @@ -1373,6 +1388,13 @@ SignalRunLoopCallback, NULL ); + if (err == 0) { + NSLog(@"Successfuly loaded signals to socket"); + hasInstalledSignalsToSocket = 1; + } + else + NSLog(@"Attempted to unsucessfully to Install signal to socket"); + } } // Create the initial client set. @@ -1429,7 +1451,8 @@ } - double resolution = 30.0; + double resolution = 0.1; + BOOL isRunning; //Add input sources to my run loop //terminateBackgroundThread is going to be set to NO before the privileged operation is called @@ -1440,10 +1463,18 @@ do { NSDate * nextDate = [NSDate dateWithTimeIntervalSinceNow:resolution]; - [currentLoop runMode:NSDefaultRunLoopMode beforeDate:nextDate]; + isRunning = [currentLoop runMode:NSDefaultRunLoopMode beforeDate:nextDate]; + //NSLog(@"running runloop"); //might add some code here to clean up and recreate autoreleasepool - } while (terminateBackgroundThread == NO); + //} while (isRunning && terminateBackgroundThread == NO); + } while (isRunning || clientHasQuit == 0); + + + //Forcibly terminate runloop N.B. ClientQuit() which is invoked + //before this call also terminates applications main runloop ... + //check to ensure that that doesn't create problems + CFRunLoopStop([currentLoop getCFRunLoop]); [sPool release]; } Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.h =================================================================== --- branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.h 2008-08-28 07:55:13 UTC (rev 39657) +++ branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.h 2008-08-28 09:25:00 UTC (rev 39658) @@ -89,6 +89,7 @@ NSFileHandle * readHandle; //BSD sockets stuff + id objectLock; BOOL terminateBackgroundThread; }
participants (1)
-
armahg@macports.org