[39562] branches/gsoc08-framework/MacPorts_Framework_Release

armahg at macports.org armahg at macports.org
Sun Aug 24 21:11:06 PDT 2008


Revision: 39562
          http://trac.macosforge.org/projects/macports/changeset/39562
Author:   armahg at macports.org
Date:     2008-08-24 21:11:06 -0700 (Sun, 24 Aug 2008)
Log Message:
-----------
HelperTool<->Framework IPC works on first build of Test bundle but not on initial builds. Time for some more troubleshooting

Modified Paths:
--------------
    branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperNotificationsProtocol.h
    branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.m

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperNotificationsProtocol.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperNotificationsProtocol.h	2008-08-24 22:58:45 UTC (rev 39561)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperNotificationsProtocol.h	2008-08-25 04:11:06 UTC (rev 39562)
@@ -177,6 +177,6 @@
 // periodically cleaned up). See SafeBindUnixDomainSocket (in "Server.c") for 
 // the details about how I achieve this.
 
-#define kServerSocketPath "/var/run/org.macports.MacPorts.Framework.MPHelperToolIPC.socket"
+#define kServerSocketPath "/var/tmp/macports/org.macports.framework.ipc.socket"
 
 #endif

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m	2008-08-24 22:58:45 UTC (rev 39561)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m	2008-08-25 04:11:06 UTC (rev 39562)
@@ -444,6 +444,7 @@
 	if (objc) {
 		NSString * data = [NSString stringWithUTF8String:Tcl_GetString(*objv)];
 		err = asl_NSLog(logClient , logMsg, ASL_LEVEL_INFO, @"MPHelperTool: %@ " , data);
+		//DoShout(<#ConnectionRef conn#>, <#const char * message#>)
 		assert(err == 0);
 		
 		returnCode = TCL_OK;
@@ -645,13 +646,15 @@
 	assert(logClient != NULL);
 	
 	
-	int             err;
+	int             err = 0;
     ConnectionRef   conn;
     conn = NULL;
     
     // SIGPIPE is evil, so tell the system not to send it to us.
     if (err == 0) {
         err = MoreUNIXIgnoreSIGPIPE();
+		asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"MPHelperTool: err started out as ZERO %i", err);
+		
     }
 	
     // Organise to have SIGINT delivered to a runloop callback.
@@ -668,11 +671,13 @@
 									SIGINTRunLoopCallback,
 									NULL
 									);
+		asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"MPHelperTool: IgnoreSigPipe Successful");
     }
     
     // Connect to the server.
     if (err == 0) {
         err = ConnectionOpen(&conn);
+		asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"MPHelperTool: Installed Signal to Socket!");
     }
     
     // Process the command line arguments.  Basically the arguments are a 
@@ -685,15 +690,17 @@
 		DoShout(conn, "Testing MPHelperTool IPC");
 	}
 	else
-		asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"MPHelperTool: calling DoShout");
+		asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"MPHelperTool: NOT calling DoShout");
 	asl_close(logClient);
 	
-    // Clean up.
-    ConnectionClose(conn);
+    
 	
 	
 	int result = BASHelperToolMain(kMPHelperCommandSet, kMPHelperCommandProcs);
 	
+	// Clean up.
+    ConnectionClose(conn);
+	
 	[pool release];
 	
 	return result;

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m	2008-08-24 22:58:45 UTC (rev 39561)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m	2008-08-25 04:11:06 UTC (rev 39562)
@@ -363,11 +363,15 @@
 }
 
 - (NSString *)evaluateStringWithPossiblePrivileges:(NSString *)statement error:(NSError **)mportError {
+	
+	
+	
 	//N.B. I am going to insist that funciton users not pass in nil for the
 	//mportError parameter
 	NSString * firstResult;
 	NSString * secondResult;
 	
+	*mportError = nil;
 	firstResult = [self evaluateStringAsString:statement error:mportError];
 	
 	//Because of string results of methods like mportsync (which returns the empty string)
@@ -375,9 +379,33 @@
 	//If it is nil then there was no error, if not we re-evaluate with privileges using
 	//the helper tool
 	
-	if (mportError != nil) {
-		* mportError = nil; 
+	if ( *mportError != nil) {
+		*mportError = nil; 
+		
+		//We need to use the notificationsObject to set up IPC with the helper tool
+		//I hope BAS's main method is blocking ... it should be since we obtain
+		//a return value
+		MPNotifications * notificationObject = [MPNotifications sharedListener];
+		if ([notificationObject respondsToSelector:@selector(prepareServerThread)]) {
+			NSLog(@"PREPARING SERVER THREAD");
+			[notificationObject prepareServerThread];
+		}
+		
+		if ([notificationObject respondsToSelector:@selector(startServerThread)]) {
+			NSThread * cThread = [NSThread currentThread];
+			NSLog(@"STARTING SERVER THREAD with previous thread %@", [cThread threadDictionary]);
+		[NSThread detachNewThreadSelector:@selector(startServerThread) 
+								 toTarget:notificationObject 
+							   withObject:nil];
+		
+		}
 		secondResult = [self evaluateStringWithMPHelperTool:statement error:mportError];
+		
+		//We can stop the thread now
+		if ([notificationObject respondsToSelector:@selector(stopServerThread)]) {
+			NSLog(@"STOPPING SERVER THREAD");
+			[notificationObject stopServerThread];
+		}
 		return secondResult;
 	}
 	

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.m	2008-08-24 22:58:45 UTC (rev 39561)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPNotifications.m	2008-08-25 04:11:06 UTC (rev 39562)
@@ -1254,6 +1254,7 @@
         err = stat(grandParentPath, &sb);
         err = MoreUNIXErrno(err);
     }
+	
     if ( (err == 0) && ( ! (sb.st_mode & S_ISTXT) || (sb.st_uid != 0) ) ) {
         fprintf(stderr, "SafeBindUnixDomainSocket: Grandparent directory (%s) is not a sticky root-owned directory.\n", grandParentPath);
         err = EINVAL;
@@ -1351,6 +1352,9 @@
 -(void) readData:(NSNotification *)notification;
 -(void) notifyWithData:(NSNotification *)notification;
 -(BOOL) initBSDSocket;
+-(void) startServerThread;
+-(void) prepareServerThread;
+-(void) stopServerThread;
 @end
 
 
@@ -1556,12 +1560,13 @@
 #pragma mark -
 #pragma mark MPNotifications Server Code - II
 
--(void) serverThreadStart {
+-(void) startServerThread {
 	NSAutoreleasePool * sPool = [[NSAutoreleasePool alloc] init];
 	
+	NSLog(@"INSIDE SERVER THREAD");
 	
 	//Configure runloop
-	int         err;
+	int         err = 0;
     int         listenerFD;
     CFSocketRef listenerCF;
     Boolean     didBind;
@@ -1571,11 +1576,14 @@
     listenerCF = NULL;
 	
 	
+	
+	
 	// Ignore SIGPIPE because it's a deeply annoying concept.  If you don't ignore 
 	// SIGPIPE when writing to a UNIX domain socket whose far side has been closed 
 	// will trigger a SIGPIPE, whose default action is to terminate the program.
     if (err == 0) {
         fprintf(stderr, "CFLocalServer: Starting up (pid: %ld).\n", (long) getpid());
+		NSLog(@"CFLocalServer: Starting up (pid: %ld).\n", (long) getpid());
         err = MoreUNIXIgnoreSIGPIPE();
     }
     
@@ -1600,20 +1608,24 @@
 	// Create the initial client set.
     if (err == 0) {
 		err = ClientInitialise();
+		NSLog(@"Initilalizing Client");
     }
     
 	// Create our listening socket, bind it, and then wrap it in a CFSocket.
     if (err == 0) {
         listenerFD = socket(AF_UNIX, SOCK_STREAM, 0);
         err = MoreUNIXErrno(listenerFD);
+		NSLog(@"Creating Socket");
     }
     if (err == 0) {
         err = SafeBindUnixDomainSocket(listenerFD, kServerSocketPath);
         didBind = (err == 0);
+		NSLog(@"Binding Socket %i", err);
     }
     if (err == 0) {
         err = listen(listenerFD, 5);
         err = MoreUNIXErrno(err);
+		NSLog(@"Listening Socket");
     }
     if (err == 0) {
         listenerCF = CFSocketCreateWithNative(
@@ -1622,6 +1634,8 @@
 											  kCFSocketAcceptCallBack, 
 											  ListeningSocketAcceptCallback, 
 											  NULL);
+		
+		NSLog(@"Creating Callbacks!");
         if (listenerCF == NULL) {
             err = EINVAL;
         }
@@ -1637,19 +1651,22 @@
             err = EINVAL;
         } else {
             CFRunLoopAddSource( [currentLoop getCFRunLoop], rls, kCFRunLoopDefaultMode);
-            
+            NSLog(@"Adding Source to current runloop");
+			
             // We no longer need this source, so we just release it.
             CFRelease(rls);
         }
     }
 	
 	
-	double resolution = 300.0;
+	double resolution = 30.0;
 	
 	//Add input sources to my run loop 
 	//terminateBackgroundThread is going to be set to NO before the privileged operation is called
 	//it will be set to YES after the privileged operation finishes execution. So I guess I need
 	//accessor methods?
+	NSThread * cThread = [NSThread currentThread];
+	NSLog(@"RUNNING RUN LOOP with thread %@" , [cThread threadDictionary]);
 	
 	do {
 		NSDate * nextDate = [NSDate dateWithTimeIntervalSinceNow:resolution];
@@ -1665,7 +1682,7 @@
 	terminateBackgroundThread == NO;
 }
 
--(void) serverThreadStop {
+-(void) stopServerThread {
 	terminateBackgroundThread == YES;
 }
 @end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080824/90cb70c6/attachment.html 


More information about the macports-changes mailing list