[launchd-changes] [23557] branches/SULeopard/launchd/src/liblaunch.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 18 10:47:38 PDT 2008


Revision: 23557
          http://trac.macosforge.org/projects/launchd/changeset/23557
Author:   zarzycki at apple.com
Date:     2008-03-18 10:47:38 -0700 (Tue, 18 Mar 2008)

Log Message:
-----------
<rdar://problem/5795236> Unix callbacks can delete the underlying control block

Modified Paths:
--------------
    branches/SULeopard/launchd/src/liblaunch.c

Modified: branches/SULeopard/launchd/src/liblaunch.c
===================================================================
--- branches/SULeopard/launchd/src/liblaunch.c	2008-03-18 17:46:21 UTC (rev 23556)
+++ branches/SULeopard/launchd/src/liblaunch.c	2008-03-18 17:47:38 UTC (rev 23557)
@@ -147,6 +147,7 @@
 static launch_data_t launch_msg_internal(launch_data_t d);
 static void launch_mach_checkin_service(launch_data_t obj, const char *key, void *context);
 
+static launch_t in_flight_msg_recv_client;
 static pthread_once_t _lc_once = PTHREAD_ONCE_INIT;
 
 static struct _launch_client {
@@ -562,6 +563,10 @@
 void
 launchd_close(launch_t lh, typeof(close) closefunc)
 {
+	if (in_flight_msg_recv_client == lh) {
+		in_flight_msg_recv_client = NULL;
+	}
+
 	if (lh->sendbuf)
 		free(lh->sendbuf);
 	if (lh->sendfds)
@@ -1009,8 +1014,16 @@
 			goto out_bad;
 		}
 
+		in_flight_msg_recv_client = lh;
+
 		cb(rmsg, context);
 
+		/* launchd and only launchd can call launchd_close() as a part of the callback */
+		if (in_flight_msg_recv_client == NULL) {
+			r = 0;
+			break;
+		}
+
 		lh->recvlen -= data_offset;
 		if (lh->recvlen > 0) {
 			memmove(lh->recvbuf, lh->recvbuf + data_offset, lh->recvlen);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080318/a7d32970/attachment.html 


More information about the launchd-changes mailing list