PERFORCE change 82316 for review

soc-tyler soc-tyler at FreeBSD.org
Sat Aug 20 09:47:11 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=82316

Change 82316 by soc-tyler at soc-tyler_launchd on 2005/08/20 09:46:41

	Pinpointing the exact problem with launchctl, error when connect to the 
	AF_UNIX socket in liblaunch.c:176 
	
	Another day, another bug :(

Affected files ...

.. //depot/projects/soc2005/launchd/liblaunch.c#9 edit

Differences ...

==== //depot/projects/soc2005/launchd/liblaunch.c#9 (text+ko) ====

@@ -132,10 +132,12 @@
 	// if we can't calloc() _lc, exit function
 	if (_lc == NULL) 
 		return;
-
+#ifdef _LAUNCHD_
+	printf("calling pthread_mutex_init() in liblaunch.c:%d\n", __LINE__);
+#endif
 	pthread_mutex_init(&_lc->mtx, NULL);
 
-	if (_launchd_fd) {
+	if (_launchd_fd != NULL) {
 		lfd = strtol(_launchd_fd, NULL, 10);
 		if ((dfd = dup(lfd)) >= 0) {
 			close(dfd);
@@ -145,17 +147,30 @@
 		}
 		unsetenv(LAUNCHD_TRUSTED_FD_ENV);
 	}
+
+#ifdef _LAUNCHD_
+	printf("Reached liblaunch.c:%d and continuing with execution from here\n", __LINE__);
+#endif	
+
 	if (lfd == -1) {
 		memset(&sun, 0, sizeof(sun));
 		sun.sun_family = AF_UNIX;
 		
-		if (where)
+		if (where != NULL)
 			strncpy(sun.sun_path, where, sizeof(sun.sun_path));
 		else
 			snprintf(sun.sun_path, sizeof(sun.sun_path), "%s/%u/sock", LAUNCHD_SOCK_PREFIX, getuid());
 
-		if ((lfd = _fd(socket(AF_UNIX, SOCK_STREAM, 0))) == -1)
+#ifdef _LAUNCHD_
+		printf("Successfully gotten the socket's path in liblaunch.c:%d\n", __LINE__);
+#endif
+
+		if ((lfd = _fd(socket(AF_UNIX, SOCK_STREAM, 0))) == -1) {
+#ifdef _LAUNCHD_
+			printf("_fd() call didn't succeed in liblaunch.c:%d\n", __LINE__);
+#endif
 			goto out_bad;
+		}
 
 		for (tries = 0; tries < 10; tries++) {
 			r = connect(lfd, (struct sockaddr *)&sun, sizeof(sun));
@@ -167,27 +182,45 @@
 				break;
 			}
 		}
+
 		if (r == -1) {
 			close(lfd);
+#ifdef _LAUNCHD_
+			printf("r was equal to -1 in liblaunch.c:%d\n", __LINE__);
+#endif
 			goto out_bad;
 		}
 	}
+
 	if (!(_lc->l = launchd_fdopen(lfd))) {
 		close(lfd);
+#ifdef _LAUNCHD_
+		printf("launchd_fdopen() failed in liblaunch.c:%d\n", __LINE__);
+#endif
 		goto out_bad;
 	}
-	if (!(_lc->async_resp = launch_data_alloc(LAUNCH_DATA_ARRAY)))
+
+	if (!(_lc->async_resp = launch_data_alloc(LAUNCH_DATA_ARRAY))) {
+#ifdef _LAUNCHD_
+		printf("launch_data_alloc() failed in liblaunch.c:%d\n", __LINE__);
+#endif
 		goto out_bad;
+	}
 
 	return;
+
 out_bad:
-	if (_lc->l)
+#ifdef _LAUNCHD_
+	printf("Executed a \"goto out_bad\", running out_bad in liblaunch.c:%d\n", __LINE__);
+#endif
+	if (_lc->l != NULL)
 		launchd_close(_lc->l);
-	if (_lc)
+	if (_lc != NULL)
 		free(_lc);
 	_lc = NULL;
-	printf("running out_bad on line: %d\n",__LINE__);
-
+#ifdef _LAUNCHD_
+	printf("Finished executing \'out_bad\', setting _lc to NULL in liblaunch.c:%d\n", __LINE__);
+#endif
 }
 
 launch_data_t launch_data_alloc(launch_data_type_t t) {
@@ -663,7 +696,7 @@
 	return 0;
 }
 
-
+//! This function is never called, therefore is empty
 int launch_get_fd(void) {
 // XXX: This function is *never* called....why does it exist?
 /*
@@ -704,7 +737,7 @@
 	// XXX: we keep evaluating for true here, and error out
 	if (_lc == NULL) {
 #ifdef _LAUNCHD_
-		printf("_lc evaluated as equal to NULL, liblaunch.c:%d\n", __LINE__);
+		printf("_lc sucks, returning liblaunch.c:%d\n", __LINE__);
 #endif	
 		errno = ENOTCONN;
 		return NULL;


More information about the p4-projects mailing list